public without sharing class SalePerformanceDataCalcUtil {

    public String currentUserNo {get; private set;}

    public SalePerformanceDataCalcUtil( ) {
        currentUserNo =[select EmployeeNumber from User where Id=: UserInfo.getUserId()].EmployeeNumber;
    }


    public static String mkregent = '迈克试剂';

    public static String regentCate = '代理';
    public static String base_post = '销售员';

    public static String cate_lj = '迈克临检';
    public static String cate_sh = '迈克生化';
    public static String cate_my = '迈克免疫';
    public static String cate_bl = '迈克病理';
    public static String cate_poct = '迈克POCT';

    public static String saler_zx = '直销销售员';
    public static String saler_fx = '分销销售员';
    public static String saler_cpx = '产品线销售员';
    public static String saler_province = '省区管理员';

    public static String saler_m_zx = '直销销售管理员';
    public static String saler_m_fx = '分销销售管理员';
    public static String saler_m_cpx = '产品线销售管理员';

    public static String equip_i3000 = 'i 3000';
    public static String equip_i1000 = 'i 1000';
    public static String equip_c800 = 'C800';
    public static String equip_xq= '血球';
    public static String equip_lx= '凝血';
    public static String equip_xx= '血型';
    public static String equip_th= '糖化';

    public static String market_zx = '终端客户';
    public static String market_fx = '经销商';
    public static String market_sf = '三方';

    public static Set<String> equipcates = new Set<String>{equip_i3000,equip_i1000,equip_c800,equip_xq,equip_lx,equip_xx,equip_th };

    public static Set<String> mkregents = new Set<String>{cate_sh,cate_my,cate_lj};
    public static Set<String> incr_sm = new Set<String>{cate_sh,cate_my};


    //绩效汇总
    public static void  calcToResult(String wono ,String year , String quater ){
         Integer qt = Integer.valueOf(quater);
        Map<String,Object> dataMap = calcAllm(wono,year,quater,true );

        //基础数据 
        //1.获取考核占比
        BaseBean br = (BaseBean) dataMap.get('baserito');
        //2.获取超期考核指标
        CalcStand cs =  getCalcStand(wono,year,quater );

        //3.基本绩效计算情况 

        //去年季度的基本绩效计算数据
        Map<Integer,BaseCalcBean> l_qBaseMap = (Map<Integer,BaseCalcBean>)dataMap.get('l_qBaseMap') ;
        //今年季度的基本绩效计算数据
        Map<Integer,BaseCalcBean> a_qBaseMap =  (Map<Integer,BaseCalcBean>)dataMap.get('a_qBaseMap') ;
        //今年季度的基本绩效预算数据
        Map<Integer,BaseCalcBean> b_qBaseMap =  (Map<Integer,BaseCalcBean>)dataMap.get('a_qBaseMap') ;
        //年度绩效
        BaseBean y_qBase = (BaseBean)dataMap.get('y_qBase');


         //去年季度的基本绩效仪器计算数据
        Map<Integer,BaseEquipCalcBean> r_eBaseMap = (Map<Integer,BaseEquipCalcBean> )dataMap.get('r_eBaseMap');
        //今年季度的基本绩效仪器计算数据
        Map<Integer,BaseEquipCalcBean> a_eBaseMap = (Map<Integer,BaseEquipCalcBean> )dataMap.get('a_eBaseMap');
        //今年季度的基本绩效仪器预算数据
        Map<Integer,BaseEquipCalcBean> b_eBaseMap = (Map<Integer,BaseEquipCalcBean> )dataMap.get('b_eBaseMap');
        //今年季度的基本绩效仪器达成率数据
        Map<Integer,BaseEquipCalcBean> c_eBaseMap = (Map<Integer,BaseEquipCalcBean> )dataMap.get('c_eBaseMap');

        BaseEquipCalcBean y_eBase = (BaseEquipCalcBean)dataMap.get('y_eBase');



        Map<Integer,IncreaseDataBean>  increase_sm = ( Map<Integer,IncreaseDataBean>)dataMap.get('increase_sm');
        Map<Integer,IncreaseDataBean>  increase_lj =( Map<Integer,IncreaseDataBean>)dataMap.get('increase_lj');
        Map<Integer,IncreaseResult> increase_targets = ( Map<Integer,IncreaseResult>)dataMap.get('increase_targets');
        //绩效结果
        Map<Integer,BaseBean> base_targets = ( Map<Integer,BaseBean>)dataMap.get('base_targets');
        //绩效结果

         //年度销售员代理增量绩效计算
        AgentResult y_agent = qt == 4 ?   (AgentResult)dataMap.get('y_agent') : new AgentResult();

        //销售管理人员增量提成（年度）
        AgentResult y_agent_m = qt == 4 ?   (AgentResult)dataMap.get('y_agent_m')  : new AgentResult();
        AgentResult y_mk_m = qt == 4 ?   (AgentResult)dataMap.get('y_mk_m')  : new AgentResult();
        
        //省区管理人员年度增量系数 
        ProvinceResult y_province =  (ProvinceResult)dataMap.get('y_province') ;

//季度绩效汇总
        List<SalesPerformanceScore__c>  qscores  = [select  Id,JobCategory__c,TheoryPerformance__c,QuarterlyContributionRate__c from SalesPerformanceScore__c
        where RecordType.DeveloperName = 'QuarterlyPerformance' and Year__c =:year and Quarter__c =:quater and EmployeeNumber__c =: wono ];
        SalesPerformanceScore__c sp = null;
        if(qscores.isEmpty() ){
            sp = new SalesPerformanceScore__c();
            sp.Name__c = br.name;
            sp.Year__c = year ; 
            sp.Quarter__c = quater;
            sp.Company__c = br.company;
            sp.EmployeeNumber__c = wono;
            sp.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('QuarterlyPerformance', 'SalesPerformanceScore__c');
        }else{
            sp = qscores[0];
        }
        //岗位
        sp.JobCategory__c = br.incr_post;
        //理论绩效
        //sp.TheoryPerformance__c 
        //(区域)
        if(sp.JobCategory__c ==  saler_zx ||
           sp.JobCategory__c ==  saler_fx ||
           sp.JobCategory__c ==  saler_cpx ||
           sp.JobCategory__c ==  saler_m_zx ||
           sp.JobCategory__c ==  saler_m_fx || System.Test.isRunningTest()){
            //迈克试剂
            sp.AreaReagent__c = base_targets.get(qt).a_mkregent_rito ;
            //仪器
            sp.AreaInstrument__c = base_targets.get(qt).a_equip_rito ;
            //代理
            sp.AreaSurrogateReagent__c =  base_targets.get(qt).a_agent_rito;
            //超期
            sp.AreaOverdue__c = base_targets.get(qt).a_overtime_rito;


        }
        //(产品线)
        if(sp.JobCategory__c ==  saler_cpx ||
            sp.JobCategory__c ==  saler_m_cpx ||
            sp.JobCategory__c ==  saler_province || System.Test.isRunningTest()
           ){
            //迈克生化
            sp.Biochemistry__c = base_targets.get(qt).p_mksh_rito;
            //迈克免疫
            sp.Immunity__c = base_targets.get(qt).p_mkmy_rito;
            //迈克临检
            sp.ClinicalLaboratory__c = base_targets.get(qt).p_mklj_rito;
            //代理
            sp.AgentProduct__c = base_targets.get(qt).p_agent_rito;
            //仪器
            sp.Instrument__c = base_targets.get(qt).p_equip_rito;
            //超期
            sp.OverdueRate__c = base_targets.get(qt).p_overtime_rito;
            //上级评价
            sp.SuperiorEvaluation__c = base_targets.get(qt).p_sjpj_rito;

        }
        //基本绩效得分
        sp.PerformanceScore__c =  base_targets.get(qt).baseResult;
        //扣款合计
        sp.DeductionAmount__c =  base_targets.get(qt).crm_minus +//crm扣款
                                 base_targets.get(qt).dz_minus +//对账扣款
                                 base_targets.get(qt).overtime_minus +//超期扣款
                                 base_targets.get(qt).performance_minus ;//绩效扣款
        
        //基本绩效发放
        sp.PerformancePayment__c = multi(sp.TheoryPerformance__c , sp.PerformancePayment__c ) + sp.DeductionAmount__c ;
        if(sp.PerformancePayment__c  < 0 ) sp.PerformancePayment__c = 0;
        //销售员季度增量绩效
        sp.QuarterlyIncrementalPerformance__c = increase_targets.get(qt).increase_rito ;
        //季度增量贡献率
        //sp.QuarterlyContributionRate__c 
        //增量发放金额
        sp.IncrementalPayment__c =sp.QuarterlyIncrementalPerformance__c;// multi(,sp.QuarterlyContributionRate__c );

        upsert sp;
//年度绩效汇总
        if(qt == 4){

            List<SalesPerformanceScore__c>  y_scores  = [select  Id,JobCategory__c,TheoryPerformance__c,
                YearContributionRate__c, RoyaltyRatio__c,AgentRoyaltyRatio__c
             from SalesPerformanceScore__c
            where RecordType.DeveloperName = 'YearPerformance' and Year__c =:year  and EmployeeNumber__c =: wono ];
            SalesPerformanceScore__c ysp = null;

            if(y_scores.isEmpty()){

                ysp = new SalesPerformanceScore__c();
                ysp.Name__c = br.name;
                ysp.Year__c = year ; 
                ysp.Company__c = br.company;
                ysp.EmployeeNumber__c = wono;
                ysp.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('YearPerformance', 'SalesPerformanceScore__c');
            }else{
                ysp = y_scores[0];
            }

            if(sp.JobCategory__c ==  saler_zx ||
               sp.JobCategory__c ==  saler_fx ||
               sp.JobCategory__c ==  saler_cpx || System.Test.isRunningTest()){

                    //销售员年度代理增量
                ysp.AgentPerformanceYear__c = y_agent.sale_rito;
                //年度贡献率
                // ysp.YearContributionRate__c
                //代理增量发放金
                ysp.AgentIncrementPayment__c = multi(ysp.AgentPerformanceYear__c ,ysp.YearContributionRate__c ); 

            }

            if(sp.JobCategory__c ==  saler_m_zx ||
                sp.JobCategory__c ==  saler_province ||
               sp.JobCategory__c ==  saler_m_fx ||
               sp.JobCategory__c ==  saler_m_cpx || System.Test.isRunningTest() ){

                //管理人员自产超额基数:自产超额 (区域 + 产品线)
                ysp.ExcessCardinality__c = y_mk_m.a_over_base+y_mk_m.p_over_base ;
                //管理人员自产提成比例
                //ysp.RoyaltyRatio__c;
                //管理人员代理超额基数:
                ysp.AgentExcessCardinality__c = y_agent_m.a_over_base + y_agent_m.p_over_base;
                //管理人员代理提成比例
                //ysp.AgentRoyaltyRatio__c

                //管理人员超额发放
                ysp.ManagerExcessPayment__c = multi(ysp.ExcessCardinality__c,ysp.RoyaltyRatio__c )+multi(ysp.AgentExcessCardinality__c,ysp.AgentRoyaltyRatio__c);

                if(sp.JobCategory__c ==  saler_province ||System.Test.isRunningTest() ){
                    //省区管理人员超额发放
                    ysp.CoefficientExcess__c = y_province.zl_rito;
                }


            }

            //年度试剂达成率 区域取 迈克试剂的达成率 : 产品线取 y_qBase 代存在生化的字段的 达成率  
            ysp.ReagentAchievementRate__c = (sp.JobCategory__c ==  saler_zx ||
                                             sp.JobCategory__c ==  saler_fx || 
                                             sp.JobCategory__c ==  saler_m_fx ||
                                             sp.JobCategory__c ==  saler_m_zx ) ? y_qBase.a_mkregent_rito : y_qBase.p_mksh_rito ;
            //年度仪器达成率
             ysp.InstrumentAchievementRate__c  = (sp.JobCategory__c ==  saler_zx ||
                                             sp.JobCategory__c ==  saler_fx || 
                                             sp.JobCategory__c ==  saler_m_fx ||
                                             sp.JobCategory__c ==  saler_m_zx ) ? y_qBase.a_equip_rito : y_qBase.p_equip_rito ;
             //区域
            //i3000
             ysp.Areai3000Rate__c  = y_eBase.a_i3000;
            //i1000
             ysp.Areai1000Rate__c  = y_eBase.a_i1000;
             //c800
             ysp.AreaC800Rate__c = y_eBase.a_c800;
             //血球
             ysp.AreaBloodCorpuscleRate__c = y_eBase.a_xq;
             //凝血
             ysp.AreaBloodClottingRate__c = y_eBase.a_lx;
             //血型
             ysp.AreaBloodTypeRate__c = y_eBase.a_xx;
             //糖化
             ysp.AreaSaccharifyRate__c = y_eBase.a_th;

              //产品线
            //i3000
             ysp.i3000Rate__c  = y_eBase.p_i3000;
            //i1000
             ysp.i1000Rate__c  = y_eBase.p_i1000;
             //c800
             ysp.C800Rate__c = y_eBase.p_c800;
             //血球
             ysp.BloodCorpuscleRate__c = y_eBase.p_xq;
             //凝血
             ysp.BloodClottingRate__c = y_eBase.p_lx;
             //血型
             ysp.BloodTypeRate__c = y_eBase.p_xx;
             //糖化
             ysp.SaccharifyRate__c = y_eBase.p_th;
             upsert ysp;


        }
        




    }

    //计算所有的绩效
    @RemoteAction
    public static String   calcAll(String wono,String year ,String quater){
        return EncodingUtil.urlEncode(JSON.serialize(calcAllm(wono,year,quater,false)), 'UTF-8') ;
    }
    
    public static  Map<String,Object>  calcAllm(String wono,String year ,String quater,boolean isBackCalc ){

        Map<String,Object> dataMap = new Map<String,Object>();
        //基础数据 
        //1.获取考核占比
        BaseBean br = getBaseRito(wono,year );
        //2.获取超期考核指标
        CalcStand cs =  getCalcStand(wono,year,quater );

        //3.基本绩效计算情况 

        //去年季度的基本绩效计算数据
        Map<Integer,BaseCalcBean> l_qBaseMap = new Map<Integer,BaseCalcBean>();

        //今年季度的基本绩效计算数据
        Map<Integer,BaseCalcBean> a_qBaseMap = new Map<Integer,BaseCalcBean>();
        //今年季度的基本绩效预算数据
        Map<Integer,BaseCalcBean> b_qBaseMap = new Map<Integer,BaseCalcBean>();

        //年度绩效
        BaseBean y_qBase = new BaseBean();

         //去年季度的基本绩效仪器计算数据
        Map<Integer,BaseEquipCalcBean> r_eBaseMap = new Map<Integer,BaseEquipCalcBean>();
        //今年季度的基本绩效仪器计算数据
        Map<Integer,BaseEquipCalcBean> a_eBaseMap = new Map<Integer,BaseEquipCalcBean>();
        //今年季度的基本绩效仪器预算数据
        Map<Integer,BaseEquipCalcBean> b_eBaseMap = new Map<Integer,BaseEquipCalcBean>();
        //今年季度的基本绩效仪器达成率数据
        Map<Integer,BaseEquipCalcBean> c_eBaseMap = new Map<Integer,BaseEquipCalcBean>();

        BaseEquipCalcBean y_eBase = new BaseEquipCalcBean();


        //区域数据 
        Map<Integer,Map<String,BaseDataSum>> arMap = new Map<Integer,Map<String,BaseDataSum>>();
        //产品线数据 
        Map<Integer,Map<String,BaseDataSum>> prMap = new Map<Integer,Map<String,BaseDataSum>>();

        Map<Integer,IncreaseDataBean>  increase_sm = new  Map<Integer,IncreaseDataBean>();
        Map<Integer,IncreaseDataBean>  increase_lj = new  Map<Integer,IncreaseDataBean>();
        Map<Integer,IncreaseResult> increase_targets = new Map<Integer,IncreaseResult>();
        //绩效结果
        Map<Integer,BaseBean> base_targets = new Map<Integer,BaseBean>();
    
        //获取并计算累计
        Integer tq = Integer.valueOf(quater);
        Integer i = 1;

        //年度销售员代理增量绩效计算
        AgentResult y_agent = tq == 4 ?   getAgentSum(wono,year,br ) : new AgentResult();

        //销售管理人员增量提成（年度）
        AgentResult y_agent_m = tq == 4 ?   getAgentSum(wono,year,br ) : new AgentResult();
        AgentResult y_mk_m = tq == 4 ?   getMkMangeSum(wono,year,br ) : new AgentResult();
        

        //省区管理人员年度增量系数 
        ProvinceResult y_province =  new ProvinceResult();
        if(tq == 4){
            BaseDataSum province_sum =  getBaseRegentSumForProvince(wono,year,br.incr_post);
            y_province.l_sale = province_sum.lq;
            y_province.b_sale = province_sum.bq;
            y_province.a_sale = province_sum.aq;
            y_province.b_increase_rito = divide(y_province.b_sale,y_province.l_sale) -1 ;
            y_province.tb_increase_rito = divide(y_province.a_sale,y_province.l_sale);

        }


        while(i <= tq){
             String qt = String.valueOf(i);
            BaseCalcBean l_qb = new BaseCalcBean('去年销售',year,qt );
            BaseCalcBean a_qb = new BaseCalcBean(year+'销售',year,qt );
            BaseCalcBean b_qb = new BaseCalcBean(year+'目标',year,qt );
           
            BaseBean target = new BaseBean();
            target.year  = year;
            target.quater =  transQuater(i);

            BaseCalcBean l_l_qb = new BaseCalcBean();
            BaseCalcBean l_a_qb = new BaseCalcBean();
            BaseCalcBean l_b_qb = new BaseCalcBean();
            //上季度 (2020年2 季度不累计 1季度的数据)
            if(i > 1 && !(i == 2 && year == '2020年') ){

                l_l_qb = l_qBaseMap.get(i-1);
                l_a_qb = a_qBaseMap.get(i-1);
                l_b_qb = b_qBaseMap.get(i-1);
            }

            //区域
            Map<String,BaseDataSum>   baseAreaSums = getBaseRegentSum(wono,year,qt,br.a_post);
            arMap.put( i, baseAreaSums);

            BaseDataSum mkSum = baseAreaSums.get(mkregent);
            if(mkSum == null )mkSum = new BaseDataSum();

            BaseDataSum shSum = baseAreaSums.get(cate_sh);
            if(shSum == null )shSum = new BaseDataSum();

            BaseDataSum mySum = baseAreaSums.get(cate_my);
            if(mySum == null )mySum = new BaseDataSum();

            BaseDataSum ljSum = baseAreaSums.get(cate_lj);
            if(ljSum == null )ljSum = new BaseDataSum();

            BaseDataSum agSum = baseAreaSums.get(cate_lj);
            if(agSum == null )agSum = new BaseDataSum();

            l_qb.a_mkregent = transDecimal(mkSum.lq,0) + l_l_qb.a_mkregent;
            l_qb.a_mksh = transDecimal(shSum.lq,0) + l_l_qb.a_mksh;
            l_qb.a_mkmy = transDecimal(mySum.lq,0) + l_l_qb.a_mkmy;
            l_qb.a_mklj = transDecimal(ljSum.lq,0) + l_l_qb.a_mklj;
            l_qb.a_agent = transDecimal(agSum.lq,0) + l_l_qb.a_agent;

            a_qb.a_mkregent = transDecimal(mkSum.aq,0)+l_a_qb.a_mkregent;
            a_qb.a_mksh = transDecimal(shSum.aq,0)+l_a_qb.a_mksh;
            a_qb.a_mkmy = transDecimal(mySum.aq,0)+l_a_qb.a_mkmy;
            a_qb.a_mklj = transDecimal(ljSum.aq,0)+l_a_qb.a_mklj;
            a_qb.a_agent = transDecimal(agSum.aq,0)+l_a_qb.a_agent;

            b_qb.a_mkregent = transDecimal(mkSum.bq,0)+l_b_qb.a_mkregent;
            b_qb.a_mksh = transDecimal(shSum.bq,0)+l_b_qb.a_mksh;
            b_qb.a_mkmy = transDecimal(mySum.bq,0)+l_b_qb.a_mkmy;
            b_qb.a_mklj = transDecimal(ljSum.bq,0)+l_b_qb.a_mklj;
            b_qb.a_agent = transDecimal(agSum.bq,0)+l_b_qb.a_agent;

            //迈克试剂
            target.a_mkregent_rito  =  calcBaseRegentRito(baseAreaSums,arMap.get(i-1), mkregent, br.post);   
            //代理
            target.a_agent_rito =   calcBaseRegentRito(baseAreaSums,arMap.get(i-1), regentCate, br.post); 
          
            //超期
            target.a_overtime_rito = cs.a_overtime_rito;

            //年度试剂达成 
            if(i == 4){

                try {
                    //if(a_qb.a_mkregent == 0 ) y_qBase.a_mkregent_rito = 0;
                    y_qBase.a_mkregent_rito =  a_qb.a_mkregent >= l_qb.a_mkregent  ? a_qb.a_mkregent / b_qb.a_mkregent : 0 ;
                    if(y_qBase.a_mkregent_rito > 1 )y_qBase.a_mkregent_rito = 1;
                }
                catch (Exception e) {
                   y_qBase.a_mkregent_rito = 0; 
                }
                

            }

            //产品线
            Map<String,BaseDataSum>   basePLineSums = getBaseRegentSum(wono,year,qt,br.p_post);
            prMap.put( i, basePLineSums);

            BaseDataSum p_mkSum = basePLineSums.get(mkregent);

            if(p_mkSum == null )p_mkSum = new BaseDataSum();
            BaseDataSum p_shSum = basePLineSums.get(cate_sh);
            if(p_shSum == null )p_shSum = new BaseDataSum();
            BaseDataSum p_mySum = basePLineSums.get(cate_my);
            if(p_mySum == null )p_mySum = new BaseDataSum();
            BaseDataSum p_ljSum = basePLineSums.get(cate_lj);
            if(p_ljSum == null )p_ljSum = new BaseDataSum();
            BaseDataSum p_agSum = basePLineSums.get(cate_lj);
            if(p_agSum == null )p_agSum = new BaseDataSum();
            
            l_qb.p_mkregent = transDecimal(p_mkSum.lq,0)+ l_l_qb.p_mkregent;
            l_qb.p_mksh = transDecimal(p_shSum.lq,0)+ l_l_qb.p_mksh;
            l_qb.p_mkmy = transDecimal(p_mySum.lq,0)+ l_l_qb.p_mkmy;
            l_qb.p_mklj = transDecimal(p_ljSum.lq,0)+ l_l_qb.p_mklj;
            l_qb.p_agent = transDecimal(p_agSum.lq,0)+ l_l_qb.p_agent;

            a_qb.p_mkregent = transDecimal(p_mkSum.aq,0)+ l_a_qb.p_mkregent;
            a_qb.p_mksh = transDecimal(p_shSum.aq,0)+ l_a_qb.p_mksh;
            a_qb.p_mkmy = transDecimal(p_mySum.aq,0)+ l_a_qb.p_mkmy;
            a_qb.p_mklj = transDecimal(p_ljSum.aq,0)+ l_a_qb.p_mklj;
            a_qb.p_agent = transDecimal(p_agSum.aq,0)+ l_a_qb.p_agent;

            b_qb.p_mkregent = transDecimal(p_mkSum.bq,0)+ l_b_qb.p_mkregent;
            b_qb.p_mksh = transDecimal(p_shSum.bq,0)+ l_b_qb.p_mksh;
            b_qb.p_mkmy = transDecimal(p_mySum.bq,0)+ l_b_qb.p_mkmy;
            b_qb.p_mklj = transDecimal(p_ljSum.bq,0)+ l_b_qb.p_mklj;
            b_qb.p_agent = transDecimal(p_agSum.bq,0)+ l_b_qb.p_agent;


            //迈克生化
            target.p_mksh_rito = calcBaseRegentRito(basePLineSums,prMap.get(i-1), cate_sh, br.post);
            //迈克免疫
            target.p_mkmy_rito = calcBaseRegentRito(basePLineSums,prMap.get(i-1), cate_my, br.post);
            //迈克临检
            target.p_mklj_rito = calcBaseRegentRito(basePLineSums,prMap.get(i-1), cate_lj, br.post);
            //代理
            target.p_agent_rito =   calcBaseRegentRito(basePLineSums, prMap.get(i-1),regentCate, br.post); 
            //仪器
            //target.p_equip_rito =   calcBaseEquipRito(getBaseEquipSum(wono,year,qt ,br.p_post),br,false );
            //超期
            target.p_overtime_rito= cs.p_overtime_rito;
            //上级评价
            target.p_sjpj_rito = cs.sjpj_rito;

            

            l_qBaseMap.put(i, l_qb);
            a_qBaseMap.put(i, a_qb);
            b_qBaseMap.put(i, b_qb);

            //仪器计算基本计算
            
            //今年
            BaseEquipCalcBean a_e = new BaseEquipCalcBean(year+'达成',year,qt );
            //今年目标
            BaseEquipCalcBean b_e = new BaseEquipCalcBean(year+'目标',year,qt);
            //今年达成统计
            BaseEquipCalcBean c_e = new BaseEquipCalcBean(year+'达成统计',year,qt);

            //今年达成率
            BaseEquipCalcBean r_e = new BaseEquipCalcBean(year+'达成率',year,qt );

            //区域
            Map<String,BaseDataSum> equipArMap = getBaseEquipSum(wono,year,qt,br.a_post);

            a_e.a_i3000 = equipArMap.containsKey(equip_i3000)  ?equipArMap.get(equip_i3000).aqe : 0;
            a_e.a_i1000  = equipArMap.containsKey(equip_i1000)  ?equipArMap.get(equip_i1000).aqe : 0;
            a_e.a_c800 = equipArMap.containsKey(equip_c800)  ?equipArMap.get(equip_c800).aqe : 0;
            a_e.a_xq = equipArMap.containsKey(equip_xq)  ?equipArMap.get(equip_xq).aqe : 0;
            a_e.a_lx = equipArMap.containsKey(equip_lx)  ?equipArMap.get(equip_lx).aqe : 0;
            a_e.a_xx = equipArMap.containsKey(equip_xx)  ?equipArMap.get(equip_xx).aqe : 0;
            a_e.a_th = equipArMap.containsKey(equip_th)  ?equipArMap.get(equip_th).aqe : 0;

            b_e.a_i3000 = equipArMap.containsKey(equip_i3000)  ? equipArMap.get(equip_i3000).bqe : 0;
            b_e.a_i1000  = equipArMap.containsKey(equip_i1000)  ? equipArMap.get(equip_i1000).bqe : 0;
            b_e.a_c800 = equipArMap.containsKey(equip_c800)  ? equipArMap.get(equip_c800).bqe : 0;
            b_e.a_xq = equipArMap.containsKey(equip_xq)  ? equipArMap.get(equip_xq).bqe : 0;
            b_e.a_lx = equipArMap.containsKey(equip_lx)  ? equipArMap.get(equip_lx).bqe : 0;
            b_e.a_xx = equipArMap.containsKey(equip_xx)  ? equipArMap.get(equip_xx).bqe : 0;
            b_e.a_th = equipArMap.containsKey(equip_th)  ? equipArMap.get(equip_th).bqe : 0;

            //产品线
            Map<String,BaseDataSum> equipPrMap = getBaseEquipSum(wono,year,qt,br.p_post);

            a_e.p_i3000 = equipPrMap.containsKey(equip_i3000)  ?equipPrMap.get(equip_i3000).aqe : 0;
            a_e.p_i1000  = equipPrMap.containsKey(equip_i1000)  ?equipPrMap.get(equip_i1000).aqe : 0;
            a_e.p_c800 = equipPrMap.containsKey(equip_c800)  ?equipPrMap.get(equip_c800).aqe : 0;
            a_e.p_xq = equipPrMap.containsKey(equip_xq)  ?equipPrMap.get(equip_xq).aqe : 0;
            a_e.p_lx = equipPrMap.containsKey(equip_lx)  ?equipPrMap.get(equip_lx).aqe : 0;
            a_e.p_xx = equipPrMap.containsKey(equip_xx)  ?equipPrMap.get(equip_xx).aqe : 0;
            a_e.p_th = equipPrMap.containsKey(equip_th)  ?equipPrMap.get(equip_th).aqe : 0;

            b_e.p_i3000 = equipPrMap.containsKey(equip_i3000)  ? equipPrMap.get(equip_i3000).bqe : 0;
            b_e.p_i1000  = equipPrMap.containsKey(equip_i1000)  ? equipPrMap.get(equip_i1000).bqe : 0;

            b_e.p_c800 = equipPrMap.containsKey(equip_c800)  ? equipPrMap.get(equip_c800).bqe : 0;
            b_e.p_xq = equipPrMap.containsKey(equip_xq)  ? equipPrMap.get(equip_xq).bqe : 0;
            b_e.p_lx = equipPrMap.containsKey(equip_lx)  ? equipPrMap.get(equip_lx).bqe : 0;
            b_e.p_xx = equipPrMap.containsKey(equip_xx)  ? equipPrMap.get(equip_xx).bqe : 0;
            b_e.p_th = equipPrMap.containsKey(equip_th)  ? equipPrMap.get(equip_th).bqe : 0;

            a_eBaseMap.put(i, a_e);
            b_eBaseMap.put(i, b_e);
            //累计达成(不包含当前) <= 累计目标(不包含当前) ? 当前达成 : 当前达成 + (累计达成(不包含当前) - 累计目标(不包含当前));
            BaseEquipCalcBean tmp = ljEquipCalc(a_eBaseMap,b_eBaseMap,i);
            c_e.a_i3000 =  tmp.a_i3000 <=0 ? a_e.a_i3000 : a_e.a_i3000 + tmp.a_i3000;
            c_e.a_i1000 =  tmp.a_c800 <=0 ? a_e.a_i1000 : a_e.a_i1000 + tmp.a_i1000;
            c_e.a_c800 =  tmp.a_c800 <=0 ? a_e.a_c800 : a_e.a_c800 + tmp.a_c800;
            c_e.a_xq =  tmp.a_xq <=0 ? a_e.a_xq : a_e.a_xq + tmp.a_xq;
            c_e.a_lx =  tmp.a_lx <=0 ? a_e.a_lx : a_e.a_lx + tmp.a_lx;
            c_e.a_xx =  tmp.a_xx <=0 ? a_e.a_xx : a_e.a_xx + tmp.a_xx;
            c_e.a_th =  tmp.a_th <=0 ? a_e.a_th : a_e.a_th + tmp.a_th;

            c_e.p_i3000 =  tmp.p_i3000 <=0 ? a_e.p_i3000 : a_e.p_i3000 + tmp.p_i3000;
            c_e.p_i1000 =  tmp.p_c800 <=0 ? a_e.p_i1000 : a_e.p_i1000 + tmp.p_i1000;
            c_e.p_c800 =  tmp.p_c800 <=0 ? a_e.p_c800 : a_e.p_c800 + tmp.p_c800;
            c_e.p_xq =  tmp.p_xq <=0 ? a_e.p_xq : a_e.p_xq + tmp.p_xq;
            c_e.p_lx =  tmp.p_lx <=0 ? a_e.p_lx : a_e.p_lx + tmp.p_lx;
            c_e.p_xx =  tmp.p_xx <=0 ? a_e.p_xx : a_e.p_xx + tmp.p_xx;
            c_e.p_th =  tmp.p_th <=0 ? a_e.p_th : a_e.p_th + tmp.p_th;
            c_eBaseMap.put(i, c_e);
            //达成率
            r_e.a_i3000 =eAchieveRito(divide(c_e.a_i3000 ,b_e.a_i3000));

            r_e.a_i1000 =eAchieveRito(divide(c_e.a_i1000 ,b_e.a_i1000));
            r_e.a_c800 =eAchieveRito(divide(c_e.a_c800 ,b_e.a_c800));
            r_e.a_xq =eAchieveRito(divide(c_e.a_xq ,b_e.a_xq));
            r_e.a_lx =eAchieveRito(divide(c_e.a_lx ,b_e.a_lx));
            r_e.a_xx =eAchieveRito(divide(c_e.a_xx ,b_e.a_xx));
            r_e.a_th =eAchieveRito(divide(c_e.a_th ,b_e.a_th));

            r_e.p_i3000 =eAchieveRito(divide(c_e.p_i3000 ,b_e.p_i3000));
            r_e.p_i1000 =eAchieveRito(divide(c_e.p_i1000 ,b_e.p_i1000));
            r_e.p_c800 =eAchieveRito(divide(c_e.p_c800 ,b_e.p_c800));
            r_e.p_xq =eAchieveRito(divide(c_e.p_xq ,b_e.p_xq));
            r_e.p_lx =eAchieveRito(divide(c_e.p_lx ,b_e.p_lx));
            r_e.p_xx =eAchieveRito(divide(c_e.p_xx ,b_e.p_xx));
            r_e.p_th =eAchieveRito(divide(c_e.p_th ,b_e.p_th));

            r_eBaseMap.put(i, r_e);

            
            //仪器
            target.a_equip_rito =   calcBaseEquipRito(r_e,b_e ,br ,true );
            target.p_equip_rito =   calcBaseEquipRito(r_e,b_e ,br ,false );


            //4.开始计算达成率
            target.baseResult = multi(target.a_mkregent_rito,br.a_mkregent_rito )
                                +multi(target.a_agent_rito,br.a_agent_rito )
                                +multi(target.a_equip_rito,br.a_equip_rito )
                                +multi(target.a_overtime_rito,br.a_overtime_rito )

                                +multi(target.p_mksh_rito,br.p_mksh_rito )
                                +multi(target.p_mkmy_rito,br.p_mkmy_rito )
                                +multi(target.p_mklj_rito,br.p_mklj_rito )
                                +multi(target.p_agent_rito,br.p_agent_rito )
                                +multi(target.p_equip_rito,br.p_equip_rito )
                                +multi(target.p_overtime_rito,br.p_overtime_rito )
                                +multi(target.p_sjpj_rito,br.p_sjpj_rito );

            target.crm_minus = br.crm_minus;
            target.dz_minus = br.dz_minus;
            target.overtime_minus = br.overtime_minus;
            target.performance_minus = br.performance_minus;

            base_targets.put(i, target);

            

            //年度试剂达成 存在生化达成的字段p_mksh_rito 上
            if(i == 4){
                //基本试剂
                y_eBase = calcEquipYearRito(a_eBaseMap,b_eBaseMap);
                BaseEquipCalcBean all_e = ljEquipCalc(b_eBaseMap);

                y_qBase.a_equip_rito = calcBaseEquipRito(y_eBase,all_e,br, true );

                y_qBase.p_equip_rito = calcBaseEquipRito(y_eBase,all_e,br, false );

               
                try {

                    y_qBase.p_mksh_rito =  a_qb.p_mkregent >= l_qb.p_mkregent  ? a_qb.p_mkregent / b_qb.p_mkregent : 0 ;
                    if(y_qBase.p_mksh_rito > 1 )y_qBase.p_mksh_rito = 1;
                }
                catch (Exception e) {
                   y_qBase.p_mksh_rito = 0; 
                }

                //销售员代理增量
                 y_agent.a_mkA_rito = divide(a_qb.a_mkregent , b_qb.a_mkregent);
                 y_agent.a_mkI_rito = divide(a_qb.a_mkregent , l_qb.a_mkregent);

                 y_agent.p_mkA_rito = divide(a_qb.p_mkregent , b_qb.p_mkregent);
                 y_agent.p_mkI_rito = divide(a_qb.p_mkregent , l_qb.p_mkregent);

                 //管理人员代理增量 
                 y_agent_m.a_mkA_rito = divide(a_qb.a_mkregent , b_qb.a_mkregent);
                 y_agent_m.a_mkI_rito = divide(a_qb.a_mkregent , l_qb.a_mkregent);
                 y_agent_m.p_mkA_rito = divide(a_qb.p_mkregent , b_qb.p_mkregent);
                 y_agent_m.p_mkI_rito = divide(a_qb.p_mkregent , l_qb.p_mkregent);

                 y_mk_m.a_mkA_rito = divide(a_qb.a_mkregent , b_qb.a_mkregent);
                 y_mk_m.a_mkI_rito = divide(a_qb.a_mkregent , l_qb.a_mkregent);
                 y_mk_m.p_mkA_rito = divide(a_qb.p_mkregent , b_qb.p_mkregent);
                 y_mk_m.p_mkI_rito = divide(a_qb.p_mkregent , l_qb.p_mkregent);


                 RitoBean ar = getAgentRito(br.company);


                if(br.incr_post == saler_zx || br.incr_post == saler_fx){
                    //提成比例
                    y_agent.a_in_rito = y_agent.a_mkA_rito >= ar.finish_rito && y_agent.a_mkI_rito >= ar.increase_rito ?  ar.a_in_rito : 0 ;
                    y_agent.a_out_rito = y_agent.a_mkA_rito >= ar.finish_rito && y_agent.a_mkI_rito >= ar.increase_rito ?  ar.a_out_rito : 0 ;

                    //提成基数
                    y_agent.a_in_base = y_agent.a_a_sale > y_agent.a_b_sale ?  y_agent.a_b_sale - y_agent.a_l_sale : y_agent.a_a_sale -   y_agent.a_l_sale ;
                    if(y_agent.a_in_base < 0)  y_agent.a_in_base  = 0;

                    y_agent.a_out_base = y_agent.a_a_sale > y_agent.a_b_sale ?y_agent.a_a_sale - y_agent.a_b_sale : 0 ;

                    //增量提成
                    y_agent.sale_rito = multi(y_agent.a_in_base,y_agent.a_in_rito)+multi(y_agent.a_out_base,y_agent.a_out_rito);

                }else if(br.incr_post == saler_cpx){

                    y_agent.p_in_rito = y_agent.p_mkA_rito >= ar.finish_rito && y_agent.p_mkI_rito >= ar.increase_rito ?  ar.p_in_rito : 0 ;
                    y_agent.p_out_rito =y_agent.p_mkA_rito >= ar.finish_rito && y_agent.p_mkI_rito >= ar.increase_rito ?   ar.p_out_rito : 0 ;

                    //提成基数
                    y_agent.p_in_base = y_agent.p_a_sale > y_agent.p_b_sale ?  y_agent.p_b_sale - y_agent.p_l_sale : y_agent.p_a_sale -   y_agent.p_l_sale ;
                    if(y_agent.p_in_base < 0)  y_agent.p_in_base  = 0;
                    y_agent.p_out_base = y_agent.p_a_sale > y_agent.p_b_sale ? y_agent.p_a_sale - y_agent.p_b_sale : 0 ;

                    //增量提成
                    y_agent.sale_rito = multi(y_agent.p_in_base,y_agent.p_in_rito)+multi(y_agent.p_out_base,y_agent.p_out_rito);
                    

                }

                if(br.incr_post == saler_m_fx || br.incr_post == saler_m_fx ){

                    y_agent_m.a_over_base = y_agent_m.a_mkA_rito >= ar.finish_rito && y_agent_m.a_mkI_rito >= ar.increase_rito ? y_agent_m.a_a_sale - y_agent_m.a_b_sale : 0 ;
                    if(y_agent_m.a_over_base  < 0 ) y_agent_m.a_over_base  = 0;

                    y_mk_m.a_over_base = y_mk_m.a_mkA_rito >= ar.finish_rito && y_mk_m.a_mkI_rito >= ar.increase_rito ? y_mk_m.a_a_sale - y_mk_m.a_b_sale : 0 ;
                    if(y_mk_m.a_over_base  < 0 ) y_mk_m.a_over_base  = 0;


                }else if(br.incr_post == saler_m_cpx){
                    y_agent_m.p_over_base = y_agent_m.p_mkA_rito >= ar.finish_rito && y_agent_m.p_mkI_rito >= ar.increase_rito ? y_agent_m.p_a_sale - y_agent_m.p_b_sale : 0 ;
                    if(y_agent_m.p_over_base < 0 )y_agent_m.p_over_base = 0;

                    y_mk_m.p_over_base = y_mk_m.p_mkA_rito >= ar.finish_rito && y_mk_m.p_mkI_rito >= ar.increase_rito ? y_mk_m.p_a_sale - y_mk_m.p_b_sale : 0 ;
                    if(y_mk_m.p_over_base < 0 )y_mk_m.p_over_base = 0;

                }

                //省区管理员
                y_province.tc_rito =(y_province.b_increase_rito+1) < ar.increase_rito ?divide(y_province.a_sale ,multi(y_province.l_sale , ar.increase_rito ) ) :  divide(y_province.a_sale,y_province.b_sale);
                  //省区管理员
                y_province.yq_rito =y_qBase.a_equip_rito;
                y_province.zl_rito =y_province.tc_rito < ar.increase_rito ? 0 : ( y_province.tc_rito > 1.3 && y_province.yq_rito > 1.2 ? 4 : ( y_province.tc_rito > 1.2 && y_province.yq_rito > 1.0 ? 2 : ( y_province.tc_rito > 1 && y_province.yq_rito > 0.8 ? 1 : 0 )  )    ); 
  

            }

            System.debug('计算季度增量:');
            //获取导入的贡献率
            List<SalesPerformanceScore__c> sscores = [select QuarterlyContributionRate__c from SalesPerformanceScore__c where EmployeeNumber__c = : wono and Year__c =: year
            and Quarter__c =:quater and RecordType.DeveloperName = 'QuarterlyPerformance' ] ;
            Decimal gxrito  = sscores.isEmpty()? 1 :transDecimal(sscores[0].QuarterlyContributionRate__c,0);
           //计算增量绩效
            Map<String,Object> increaseMap  = calcIncrease(wono,year,qt,gxrito,br,a_qb,l_qb );

            increase_sm.put(i, (IncreaseDataBean)increaseMap.get(cate_sh));
            increase_lj.put(i, (IncreaseDataBean)increaseMap.get(cate_lj));
            increase_targets.put(i, (IncreaseResult)increaseMap.get('target'));
            i ++;

        }

        dataMap.put('l_qBaseMap', ( isBackCalc ? (Object)l_qBaseMap : (Object)l_qBaseMap.values()) );
        dataMap.put('a_qBaseMap',isBackCalc ? (Object)a_qBaseMap : (Object)a_qBaseMap.values() );
        dataMap.put('b_qBaseMap',isBackCalc ? (Object)b_qBaseMap : (Object)b_qBaseMap.values() );

        dataMap.put('a_eBaseMap',isBackCalc ? (Object)a_eBaseMap : (Object)a_eBaseMap.values() );
        dataMap.put('b_eBaseMap',isBackCalc ? (Object)b_eBaseMap : (Object)b_eBaseMap.values() );
        dataMap.put('c_eBaseMap',isBackCalc ? (Object)c_eBaseMap : (Object)c_eBaseMap.values() );
        dataMap.put('r_eBaseMap',isBackCalc ? (Object)r_eBaseMap : (Object)r_eBaseMap.values() );

        dataMap.put('base_targets',isBackCalc ? (Object)base_targets : (Object)base_targets.values() );
        dataMap.put('y_qBase',y_qBase );
        dataMap.put('y_eBase',y_eBase );

        dataMap.put('y_agent',y_agent );
        dataMap.put('y_agent_m',y_agent_m );
        dataMap.put('y_mk_m',y_mk_m );
        dataMap.put('y_province',y_province );

        dataMap.put('increase_targets',isBackCalc ? (Object)increase_targets : (Object)increase_targets.values() );
        dataMap.put('increase_sm',isBackCalc ? (Object)increase_sm :  (Object)increase_sm.values() );
        dataMap.put('increase_lj',isBackCalc ? (Object)increase_lj : (Object)increase_lj.values() );
        dataMap.put('baserito',br );
        dataMap.put('company', ImportObject.getPicklistValues('SalesPerformanceDataSheet__c','Company__c', true));
        return  dataMap;// EncodingUtil.urlEncode(JSON.serialize(dataMap), 'UTF-8') ;
    }

    public static BaseEquipCalcBean ljEquipCalc(Map<Integer,BaseEquipCalcBean> a_eMap ){
        BaseEquipCalcBean a_tmp = new BaseEquipCalcBean();
        for (Integer i  : a_eMap.keySet()) {
            a_tmp.a_i3000 += a_eMap.get(i).a_i3000;
            a_tmp.a_i1000 += a_eMap.get(i).a_i1000;
            a_tmp.a_c800 += a_eMap.get(i).a_c800;
            a_tmp.a_xq += a_eMap.get(i).a_xq;
            a_tmp.a_lx += a_eMap.get(i).a_lx;
            a_tmp.a_xx += a_eMap.get(i).a_xx;
            a_tmp.a_th += a_eMap.get(i).a_th;

            a_tmp.p_i3000 += a_eMap.get(i).p_i3000;
            a_tmp.p_i1000 += a_eMap.get(i).p_i1000;
            a_tmp.p_c800 += a_eMap.get(i).p_c800;
            a_tmp.p_xq += a_eMap.get(i).p_xq;
            a_tmp.p_lx += a_eMap.get(i).p_lx;
            a_tmp.p_xx += a_eMap.get(i).p_xx;
            a_tmp.p_th += a_eMap.get(i).p_th;
        }
        return a_tmp;

    }
    public static BaseEquipCalcBean calcEquipYearRito(Map<Integer,BaseEquipCalcBean> a_eMap ,Map<Integer,BaseEquipCalcBean> b_eMap ){
        BaseEquipCalcBean y_eBase = new BaseEquipCalcBean();
        if(a_eMap.size() < 4) return y_eBase;
        BaseEquipCalcBean a_tmp = ljEquipCalc(a_eMap);//new BaseEquipCalcBean();
        BaseEquipCalcBean b_tmp = ljEquipCalc(b_eMap);//new BaseEquipCalcBean();
        y_eBase.a_i3000 = divide( a_tmp.a_i3000 , b_tmp.a_i3000 ) ;
        y_eBase.a_i1000 = divide( a_tmp.a_i1000 , b_tmp.a_i1000 ) ;
        y_eBase.a_c800 = divide( a_tmp.a_c800 , b_tmp.a_c800 ) ;
        y_eBase.a_xq = divide( a_tmp.a_xq , b_tmp.a_xq ) ;
        y_eBase.a_lx = divide( a_tmp.a_lx , b_tmp.a_lx ) ;
        y_eBase.a_xx = divide( a_tmp.a_xx , b_tmp.a_xx ) ;
        y_eBase.a_th = divide( a_tmp.a_th , b_tmp.a_th ) ;

        y_eBase.p_i3000 = divide( a_tmp.p_i3000 , b_tmp.p_i3000 ) ;
        y_eBase.p_i1000 = divide( a_tmp.p_i1000 , b_tmp.p_i1000 ) ;
        y_eBase.p_c800 = divide( a_tmp.p_c800 , b_tmp.p_c800 ) ;
        y_eBase.p_xq = divide( a_tmp.p_xq , b_tmp.p_xq ) ;
        y_eBase.p_lx = divide( a_tmp.p_lx , b_tmp.p_lx ) ;
        y_eBase.p_xx = divide( a_tmp.p_xx , b_tmp.p_xx ) ;
        y_eBase.p_th = divide( a_tmp.p_th , b_tmp.p_th ) ;

        if(y_eBase.a_i3000 > 1.2) y_eBase.a_i3000 = 1.2;
        if(y_eBase.a_i1000 > 1.2) y_eBase.a_i1000 = 1.2;
        if(y_eBase.a_c800 > 1.2) y_eBase.a_c800 = 1.2;
        if(y_eBase.a_xq > 1.2) y_eBase.a_xq = 1.2;
        if(y_eBase.a_lx > 1.2) y_eBase.a_lx = 1.2;
        if(y_eBase.a_xx > 1.2) y_eBase.a_xx = 1.2;
        if(y_eBase.a_th > 1.2) y_eBase.a_th = 1.2;

        if(y_eBase.p_i3000 > 1.2) y_eBase.p_i3000 = 1.2;
        if(y_eBase.p_i1000 > 1.2) y_eBase.p_i1000 = 1.2;
        if(y_eBase.p_c800 > 1.2) y_eBase.p_c800 = 1.2;
        if(y_eBase.p_xq > 1.2) y_eBase.p_xq = 1.2;
        if(y_eBase.p_lx > 1.2) y_eBase.p_lx = 1.2;
        if(y_eBase.p_xx > 1.2) y_eBase.p_xx = 1.2;
        if(y_eBase.p_th > 1.2) y_eBase.p_th = 1.2;

        return y_eBase;
    }
    public static Decimal eAchieveRito(Decimal r ){
        return r <= 0.8 ? r : 1;
    }
    public static Decimal divide(Decimal a ,Decimal b ){
        if(a == null || b == null || b == 0) return 0;
        return a / b ;
    }
    public static  BaseEquipCalcBean ljEquipCalc(Map<Integer,BaseEquipCalcBean> aMap , Map<Integer,BaseEquipCalcBean> bMap,Integer i  ){
       BaseEquipCalcBean r = new BaseEquipCalcBean();
        if(i == 1)return r;

        for (Integer k : aMap.keySet() ) {
            if(k < i ){

                r.a_i3000 += aMap.get(k).a_i3000 - bMap.get(k).a_i3000 ;
                r.a_i1000 += aMap.get(k).a_i1000- bMap.get(k).a_i1000 ;
                r.a_c800 += aMap.get(k).a_c800- bMap.get(k).a_c800 ;
                r.a_xq += aMap.get(k).a_xq- bMap.get(k).a_xq ;
                r.a_lx += aMap.get(k).a_lx- bMap.get(k).a_lx ;
                r.a_xx += aMap.get(k).a_xx- bMap.get(k).a_xx ;
                r.a_th += aMap.get(k).a_th- bMap.get(k).a_th ;

                r.p_i3000 += aMap.get(k).p_i3000 - bMap.get(k).p_i3000 ;
                r.p_i1000 += aMap.get(k).p_i1000- bMap.get(k).p_i1000 ;
                r.p_c800 += aMap.get(k).p_c800- bMap.get(k).p_c800 ;
                r.p_xq += aMap.get(k).p_xq- bMap.get(k).p_xq ;
                r.p_lx += aMap.get(k).p_lx- bMap.get(k).p_lx ;
                r.p_xx += aMap.get(k).p_xx- bMap.get(k).p_xx ;
                r.p_th += aMap.get(k).p_th- bMap.get(k).p_th ;
                
            }
        }
        return r ;

    }



    //计算基本绩效仪器的达成率
     public static Decimal  calcBaseEquipRito(BaseEquipCalcBean r_e,BaseEquipCalcBean b_e  ,BaseBean br,Boolean isArea  ){
        try {
            
            
            Decimal totalup =isArea  ?  multi(br.a_i3000_rito , r_e.a_i3000)
                               +multi(br.a_i1000_rito , r_e.a_i1000)
                               +multi(br.a_c800_rito , r_e.a_c800)
                               +multi(br.a_xq_rito , r_e.a_xq)
                               +multi(br.a_lx_rito , r_e.a_lx)
                               +multi(br.a_xx_rito , r_e.a_xx)
                               +multi(br.a_th_rito , r_e.a_th) :

                                multi(br.p_i3000_rito , r_e.p_i3000)
                               +multi(br.p_i1000_rito , r_e.p_i1000)
                               +multi(br.p_c800_rito , r_e.p_c800)
                               +multi(br.p_xq_rito , r_e.p_xq)
                               +multi(br.p_lx_rito , r_e.p_lx)
                               +multi(br.p_xx_rito , r_e.p_xx)
                               +multi(br.p_th_rito , r_e.p_th)
                               ;
            Decimal totaldown = isArea  ?  backZero(b_e.a_i3000, br.a_i3000_rito )
                             +backZero(b_e.a_i1000, br.a_i1000_rito )
                             +backZero(b_e.a_c800, br.a_c800_rito )
                             +backZero(b_e.a_xq, br.a_xq_rito )
                             +backZero(b_e.a_lx, br.a_lx_rito )
                             +backZero(b_e.a_xx, br.a_xx_rito )
                             +backZero(b_e.a_th, br.a_th_rito ) : 

                              backZero(b_e.p_i3000, br.p_i3000_rito )
                             +backZero(b_e.p_i1000, br.p_i1000_rito )
                             +backZero(b_e.p_c800, br.p_c800_rito )
                             +backZero(b_e.p_xq, br.p_xq_rito )
                             +backZero(b_e.p_lx, br.p_lx_rito )
                             +backZero(b_e.p_xx, br.p_xx_rito )
                             +backZero(b_e.p_th, br.p_th_rito );
            return divide(totalup,totaldown);

        }catch (Exception e) {
            System.debug('calcBaseEquipRito=>'+e.getMessage()+e.getStackTraceString());
            return 0;
        }
        

     }

     public static Decimal backZero(Decimal a , Decimal b ){
        if(a == 0 || b == 0 || a == null || b == null ) return 0;
        return b ;
     }
     public static Decimal  calcBaseEquipRito(Map<String,BaseDataSum> sumMap ,BaseBean br ,Boolean isArea ){



        Map<String,Decimal> ritoMap = isArea ? br.aRitoMap : br.pRitoMap;
        if(ritoMap == null) return 0; 
        Decimal totalup = 0;
        Decimal totaldown = 0;
        for (String spec  : sumMap.keySet() ) {
                //达成率
                Decimal ertio = sumMap.get(spec).ertio;
                //占比
                Decimal rito = ritoMap.get(spec);
                //目标为0 ? 0 : 占比
                totaldown +=  (sumMap.get(spec).bqe == 0 || sumMap.get(spec).bqe == null  ? 0 : rito);

            try {
                totalup += ertio* rito;
            }catch (Exception e) {}

        }
        return totaldown == 0 ? 0 : totalup / totaldown;

     }
    //计算基本绩效试剂的达成率
    public static Decimal calcBaseRegentRito(Map<String,BaseDataSum> sumMap ,String cate ,String post ){
        BaseDataSum bs= sumMap.get(cate);
        if(bs == null)return 0;
        //如果目标为0 则达成率为 0;
        if(bs.bq == 0) return 0;
        //是不是销售员
        boolean isSaler = post == base_post;
        //销售员 ? 今年>去年  : 今年 / 今年目标
        Decimal r = isSaler ? (bs.aq >= bs.lq ? 1 : 0 ) : (bs.aq >= bs.lq ?  ( bs.aq / bs.bq  ) : 0 );

        return  r < 1 ? r : 1;
    }


     //计算基本绩效试剂的达成率
    public static Decimal calcBaseRegentRito(Map<String,BaseDataSum> bsM , Map<String,BaseDataSum> l_bsM ,String cate ,String post ){
        
        BaseDataSum l_bs =l_bsM == null ? null :  l_bsM.get(cate);
        if(l_bs == null ) l_bs = new BaseDataSum();
       
        BaseDataSum bs= bsM.get(cate);
        if(bs == null)return 0;

        //如果目标为0 则达成率为 0;
        Decimal aq = bs.aq +l_bs.aq;
        Decimal lq = bs.lq +l_bs.lq;
        Decimal bq = bs.bq +l_bs.bq;
        if(bq == 0) return 0;

        //if(bs.bq == 0) return 0;
        //是不是销售员
        boolean isSaler = post == base_post;
        //销售员 ? 今年>去年  : 今年 / 今年目标
        Decimal r = isSaler ? (aq >= lq ? 1 : 0 ) : (aq >= lq ?  ( aq / bq  ) : 0 );
       // Decimal r = isSaler ? (bs.aq >= bs.lq ? 1 : 0 ) : (bs.aq >= bs.lq ?  ( bs.aq / bs.bq  ) : 0 );
        return  r < 1 ? r : 1;
    }
   
    public static   Map<String, Object> calcIncrease(String wono ,String year ,String quater,Decimal gxrito, BaseBean br, BaseCalcBean a_b, BaseCalcBean l_b   ){
        IncreaseResult target =new IncreaseResult();
        target.year = year;
        target.quater = quater;
        //1.区域销售
        Map<String,List<IncreaseData>> res = getIncreaseData(wono,year,quater,br );
        IncreaseDataBean ins_sm = new IncreaseDataBean ();//生免
        ins_sm.year = year;
        ins_sm.quater = quater;
        ins_sm.cate = '生免产品线增量';
        IncreaseDataBean ins_lj = new IncreaseDataBean ();//临检
        ins_lj.year = year;
        ins_lj.quater = quater;
        ins_lj.cate = '临检产品线增量';

        if(br.incr_post != saler_cpx){

            for (String cate  : res.keySet()) {
            
                List<IncreaseData> i_datas = res.get(cate);
                for ( IncreaseData i : i_datas ) {

                   if(incr_sm.contains(cate)){
                        if(i.type == '特殊项目'){
                            ins_sm.a_l_special_sale += transDecimal(i.lq ,0);//+transDecimal(ins_sm.a_l_special_sale ,0) ;
                            ins_sm.a_a_special_sale += transDecimal(i.aq,0);//+transDecimal(ins_sm.a_a_special_sale ,0) ;

                        }else if(i.type == '非特殊项目'){
                            ins_sm.a_l_normal_sale += transDecimal(i.lq,0);//+transDecimal(ins_sm.a_l_normal_sale ,0) ;
                            ins_sm.a_a_normal_sale += transDecimal(i.aq,0);//+transDecimal(ins_sm.a_a_normal_sale ,0) ;
                        }           

                   }else if(cate_lj == cate ){

                        if(i.type == '特殊项目'){
                            ins_lj.a_l_special_sale +=transDecimal(i.lq ,0);// transDecimal(ins_lj.a_l_special_sale,0)+transDecimal(ins_lj.a_l_special_sale ,0) ;
                            ins_lj.a_a_special_sale +=transDecimal(i.aq ,0);// transDecimal(ins_lj.a_a_special_sale,0)+transDecimal(ins_lj.a_a_special_sale ,0) ;

                        }else if(i.type == '非特殊项目'){
                            ins_lj.a_l_normal_sale = transDecimal(i.lq ,0);//transDecimal(ins_lj.a_l_normal_sale,0)+transDecimal(ins_lj.a_l_normal_sale ,0) ;
                            ins_lj.a_a_normal_sale = transDecimal(i.aq ,0);//transDecimal(ins_lj.a_a_normal_sale,0)+transDecimal(ins_lj.a_a_normal_sale ,0) ;
                        }

                   } 

                }
            }

             //增长率
            try {
                ins_sm.a_increase_rito = divide ((transDecimal(a_b.a_mksh,0 )+transDecimal(a_b.a_mkmy,0) ) , (transDecimal(l_b.a_mksh,0)+transDecimal(l_b.a_mkmy,0) ));
                //if(ins_sm.a_increase_rito != 0 )ins_sm.a_increase_rito -= 1;
            }
            catch (Exception e) {
                ins_sm.a_increase_rito = 0;
            }

            try {
                ins_lj.a_increase_rito = divide(a_b.a_mklj , l_b.a_mklj);
                //if(ins_lj.a_increase_rito != 0 )ins_lj.a_increase_rito -= 1;
            }
            catch (Exception e) {
                ins_lj.a_increase_rito = 0;
            }
            //提成比例
            RitoBean rb = getIncreaseRito(br.company,cate_sh,ins_sm.a_increase_rito ) ;
            ins_sm.special_rito = rb.a_special_rito;
            ins_sm.normal_rito = rb.a_normal_rito;

            //提成比例
            RitoBean rb_lj = getIncreaseRito(br.company,cate_lj,ins_lj.a_increase_rito ) ;
            ins_lj.special_rito = rb_lj.a_special_rito;
            ins_lj.normal_rito = rb_lj.a_normal_rito;

            //


        }else{ //2.产品线销售

            for (String cate  : res.keySet()) {
            
                List<IncreaseData> i_datas = res.get(cate);
                for ( IncreaseData i : i_datas ) {

                   if(incr_sm.contains(cate)){
                        if(i.type == '特殊项目'){
                            ins_sm.p_l_special_sale +=transDecimal(i.lq ,0);// transDecimal(ins_sm.p_l_special_sale,0)+transDecimal(ins_sm.p_l_special_sale ,0) ;
                            ins_sm.p_a_special_sale +=transDecimal(i.aq ,0);// transDecimal(ins_sm.p_a_special_sale,0)+transDecimal(ins_sm.p_a_special_sale ,0) ;

                        }else if(i.type == '非特殊项目'){
                            ins_sm.p_l_normal_sale =transDecimal(i.lq ,0);// transDecimal(ins_sm.p_l_normal_sale,0)+transDecimal(ins_sm.p_l_normal_sale ,0) ;
                            ins_sm.p_a_normal_sale = transDecimal(i.aq ,0);//transDecimal(ins_sm.p_a_normal_sale,0)+transDecimal(ins_sm.p_a_normal_sale ,0) ;
                        }           

                   }else if(cate_lj == cate ){

                        if(i.type == '特殊项目'){
                            ins_lj.p_l_special_sale += transDecimal(i.lq ,0);//transDecimal(ins_lj.p_l_special_sale,0)+transDecimal(ins_lj.p_l_special_sale ,0) ;
                            ins_lj.p_a_special_sale += transDecimal(i.aq ,0);//transDecimal(ins_lj.p_a_special_sale,0)+transDecimal(ins_lj.p_a_special_sale ,0) ;

                        }else if(i.type == '非特殊项目'){
                            ins_lj.p_l_normal_sale = transDecimal(i.lq ,0);//transDecimal(ins_lj.p_l_normal_sale,0)+transDecimal(ins_lj.p_l_normal_sale ,0) ;
                            ins_lj.p_a_normal_sale = transDecimal(i.aq ,0);//transDecimal(ins_lj.p_a_normal_sale,0)+transDecimal(ins_lj.p_a_normal_sale ,0) ;
                        }

                   } 

                }
            }

            //增长率
           
            try {

                ins_sm.p_increase_rito =divide(( a_b.p_mksh+ a_b.p_mkmy ) ,( l_b.p_mksh + l_b.p_mkmy )  )  ;
               // if(ins_sm.p_increase_rito != 0 )ins_sm.p_increase_rito -= 1;

            }catch (Exception e) {
                ins_sm.p_increase_rito = 0;
            }

            try {
                ins_lj.p_increase_rito =divide(a_b.p_mklj,l_b.a_mklj);//transDecimal(p_lj == null  ? 0 : p_lj.aq,0) / transDecimal(p_lj == null  ? 0 : p_lj.lq,0);
               // if(ins_lj.p_increase_rito != 0 )ins_lj.p_increase_rito -= 1;
            }
            catch (Exception e) {
                ins_lj.p_increase_rito = 0;
            }

            //提成比例
            RitoBean rb = getIncreaseRito(br.company,cate_sh,ins_sm.p_increase_rito ) ;
            ins_sm.special_rito = rb.p_special_rito;
            ins_sm.normal_rito = rb.p_normal_rito;

            //提成比例
            RitoBean rb_lj = getIncreaseRito(br.company,cate_lj,ins_lj.p_increase_rito ) ;
            ins_lj.special_rito = rb_lj.p_special_rito;
            ins_lj.normal_rito = rb_lj.p_normal_rito;

        }
        
        


        //特殊项目基数 生免
        ins_sm.special_base = 0;
         //特殊项目基数 临检
        ins_lj.special_base  = 0;
        
        if( br.incr_post == saler_cpx) {

            ins_sm.special_base = ins_sm.p_a_special_sale - ins_sm.p_l_special_sale + ( ins_sm.p_a_normal_sale < ins_sm.p_l_normal_sale ? ins_sm.p_a_normal_sale - ins_sm.p_l_normal_sale :0  );
            ins_lj.special_base = ins_lj.p_a_special_sale - ins_lj.p_l_special_sale + ( ins_lj.p_a_normal_sale < ins_lj.p_l_normal_sale ? ins_lj.p_a_normal_sale - ins_lj.p_l_normal_sale :0  );

        }else if( br.incr_post == saler_zx || br.incr_post == saler_fx  ){

            ins_sm.special_base = ins_sm.a_a_special_sale - ins_sm.a_l_special_sale + ( ins_sm.a_a_normal_sale < ins_sm.a_l_normal_sale ? ins_sm.a_a_normal_sale - ins_sm.a_l_normal_sale :0  );
            ins_lj.special_base = ins_lj.a_a_special_sale - ins_lj.a_l_special_sale + ( ins_lj.a_a_normal_sale < ins_lj.a_l_normal_sale ? ins_lj.a_a_normal_sale - ins_lj.a_l_normal_sale :0  );
       }
        if(ins_sm.special_base < 0 ) ins_sm.special_base = 0 ; 
        if(ins_lj.special_base < 0 ) ins_lj.special_base = 0 ; 

         //非特殊项目基数 生免
        ins_sm.normal_base = 0;
         //非特殊项目基数 临检
        ins_lj.normal_base  = 0;
        
        if( br.incr_post == saler_cpx) {

            ins_sm.normal_base = ins_sm.p_a_normal_sale - ins_sm.p_l_normal_sale + ( ins_sm.p_a_special_sale < ins_sm.p_l_special_sale ? ins_sm.p_a_special_sale - ins_sm.p_l_special_sale :0  );
            ins_lj.normal_base = ins_lj.p_a_normal_sale - ins_lj.p_l_normal_sale + ( ins_lj.p_a_special_sale < ins_lj.p_l_special_sale ? ins_lj.p_a_special_sale - ins_lj.p_l_special_sale :0  );

        }else if( br.incr_post == saler_zx || br.incr_post == saler_fx  ){

            ins_sm.normal_base = ins_sm.a_a_normal_sale - ins_sm.a_l_normal_sale + ( ins_sm.a_a_special_sale < ins_sm.a_l_special_sale ? ins_sm.a_a_special_sale - ins_sm.a_l_special_sale :0  );
            ins_lj.normal_base = ins_lj.a_a_normal_sale - ins_lj.a_l_normal_sale + ( ins_lj.a_a_special_sale < ins_lj.a_l_special_sale ? ins_lj.a_a_special_sale - ins_lj.a_l_special_sale :0  );

       }
        if(ins_sm.normal_base < 0 ) ins_sm.normal_base = 0 ; 
        if(ins_lj.normal_base < 0 ) ins_lj.normal_base = 0 ; 

        ins_sm.sale_rito = multi(ins_sm.special_base,ins_sm.special_rito) + multi(ins_sm.normal_base,ins_sm.normal_rito);
        ins_lj.sale_rito = multi(ins_lj.special_base,ins_lj.special_rito) + multi(ins_lj.normal_base,ins_lj.normal_rito);

        target.increase_rito = ins_sm.sale_rito + ins_lj.sale_rito ;

        target.rito =  gxrito;//贡献率

        target.money_rito = multi(target.increase_rito ,target.rito );//增量发放
        Map<String, Object> calcM = new Map<String,Object>();
        calcM.put(cate_sh,ins_sm );
        calcM.put(cate_lj,ins_lj );
        calcM.put('target',target );

        return calcM ;
    }


    //获取代理提成比例
    public static RitoBean getAgentRito(String company  ){
        RitoBean r = new RitoBean();
        r.a_in_rito = company == 'MKSY' ? 0.0075 : (company == 'SHMK' ? 0 : 0.01);
        r.a_out_rito = company == 'MKSY' ? 0.015 : (company == 'SHMK' ? 0 : 0.02);

        r.p_in_rito = company == 'MKSY' ? 0.0025 : (company == 'SHMK' ? 0 : 0.01);
        r.p_out_rito = company == 'MKSY' ? 0.005 : (company == 'SHMK' ? 0 : 0.02);
        r.finish_rito = 1;
        r.increase_rito = company == 'SDMK' ? 1.4 : (company == 'MKSY' ? 1.15 : 1.2);
        return r ; 
    }
    //获取自产提成比例
    public static RitoBean getIncreaseRito(String company , String cate,Decimal rito ){
        RitoBean r  =  new RitoBean(0,0,0,0);
        //Decimal a_nr ,Decimal a_sr ,Decimal p_nr ,Decimal p_sr 
        if(cate == cate_sh || cate == cate_my){
            if(rito < 1)r = new RitoBean(0,0,0,0);
            if(rito < 1.15 )r = new RitoBean(company == 'MKSY' ? 0.0075 : 0.01 ,company == 'MKSY' ? 0.015: 0.02 ,company == 'MKSY' ? 0.0025 : 0.01 , company == 'MKSY' ? 0.005 : 0.02 );
            if(rito < 1.40 )r = new RitoBean(company == 'MKSY' ? 0.015 : 0.02 ,company == 'MKSY' ? 0.03: 0.04 ,company == 'MKSY' ? 0.005 : 0.02 , company == 'MKSY' ? 0.01 : 0.04 );
            r = new RitoBean(0.03 ,company == 'MKSY' ? 0.0375: 0.05 ,company == 'MKSY' ? 0.0075 : 0.03 , company == 'MKSY' ? 0.0125 : 0.05 );
        }else if(cate == cate_lj){

            if(rito < 1)r = new RitoBean(0,0,0,0);

            if(rito < 1.15 )r = new RitoBean(company == 'MKSY' ? 0.015 : 0.02 , 0.03 ,company == 'MKSY' ? 0.005 : 0.02 , company == 'MKSY' ? 0.01 : 0.03 );

            if(rito < 1.40 )r = new RitoBean(0.03 ,company == 'MKSY' ? 0.0375: 0.05 ,company == 'MKSY' ? 0.0075 : 0.03 , company == 'MKSY' ? 0.0125 : 0.05 );

            r = new RitoBean(company == 'MKSY' ? 0.0375: 0.05 ,company == 'MKSY' ? 0.0225 : 0.07 , company == 'MKSY' ? 0.0125 : 0.05, company == 'MKSY' ? 0.0175 : 0.07 );

        }
        return r ;
    }

    public static Decimal multi(Decimal a ,Decimal b){
        if(a == null || b == null) return 0;
        return a * b ;
    }

    //获取考核指标
    public static CalcStand getCalcStand(String wono,String year,String quater  ){
        CalcStand  cs = new CalcStand();
        List<SalesPerformanceDataSheet__c> dss = [select Id ,OverdueScore__c , AreaOverdueScore__c , 
        SuperiorEvaluation__c,ReceivableDeduction__c,CRMDeduction__c,OverdueDeduction__c,MeasurementDeduction__c
        from SalesPerformanceDataSheet__c where EmployeeNumber__c =:wono 
        And Year__c =:year And Quarter__c =:quater  and RecordType.DeveloperName = 'PerformanceTargetScore' limit 1 ];
        if(dss.isEmpty())return cs;

    	cs.a_overtime_rito =transDecimal(dss[0].AreaOverdueScore__c,0 ) ;
    	cs.p_overtime_rito = transDecimal(dss[0].OverdueScore__c,0 ) ;
        cs.crm_minus = transDecimal(dss[0].CRMDeduction__c,0 ) ;
        cs.dz_minus = transDecimal(dss[0].ReceivableDeduction__c,0 ) ;
        cs.overtime_minus = transDecimal(dss[0].OverdueDeduction__c,0 ) ;
        cs.sjpj_rito = transDecimal(dss[0].SuperiorEvaluation__c,0 ) ;

        cs.performance_minus = transDecimal(dss[0].MeasurementDeduction__c,0 ) ;

    	return cs;

    }


    public static Decimal transPercentToDecimal(Decimal d){
        return d;
    }
    //管理人员自产试剂增量
    public static AgentResult getMkMangeSum(String wono , String year , BaseBean br  ){
         String post = br.incr_post ;
         AgentResult ar = new AgentResult();
       if(String.isBlank(post) ||  (post != saler_m_cpx  && post != saler_m_zx && post != saler_m_fx ) ) return ar ; 
       
        Set<String> markets = post == saler_cpx ?  new Set<String>{market_zx,market_fx} : post == saler_zx ? new Set<String>{market_zx} : new Set<String>{market_fx}   ;
        
        for(AggregateResult arg : [select  
             sum(ActualSales__c) asum,sum(BudgetSales__c) bsum  
            from SalesPerformanceDataSheet__c where EmployeeNumber__c =:wono and Year__c =:year and JobCategory__c =:post  and SalesMarket__c in: markets
             and RecordType.DeveloperName in ('AnnualIncrementPerformance','AnnualIncrementPerformanceAdjust') and NotActive__c = false 
             ]){
            if(post != saler_cpx){

                ar.a_a_sale = Decimal.valueOf((String)arg.get('asum'));
                ar.a_b_sale = Decimal.valueOf((String)arg.get('bsum'));

            }else{
                ar.p_a_sale = Decimal.valueOf((String)arg.get('asum'));
                ar.p_b_sale = Decimal.valueOf((String)arg.get('bsum'));
            }

        }
        return ar;

    }

    //销售员试剂代理增量年度绩效
    public static AgentResult getAgentSum(String wono , String year , BaseBean br  ){
         String post = br.incr_post ;
         AgentResult ar = new AgentResult();
       if(String.isBlank(post) ||  (post != saler_cpx  && post != saler_zx && post != saler_fx && post != saler_m_cpx  && post != saler_m_zx && post != saler_m_fx  )  ) return ar ; 
       
        Set<String> markets = post == saler_cpx ?  new Set<String>{market_zx,market_fx} : post == saler_zx ? new Set<String>{market_zx} : new Set<String>{market_fx}   ;
        
        for(AggregateResult arg : [select  
            sum(LastYearSalesVolume__c) lsum , sum(ActualSales__c) asum,sum(BudgetSales__c) bsum  
            from SalesPerformanceDataSheet__c where EmployeeNumber__c =:wono and Year__c =:year and JobCategory__c =:post  and SalesMarket__c in: markets
             and RecordType.DeveloperName in ('AgentIncrementPerformanceAdjust','AgentIncrementPerformance') and NotActive__c = false 
             ]){
            if(post != saler_cpx){
                ar.a_l_sale = Decimal.valueOf((String)arg.get('lsum'));
                ar.a_a_sale = Decimal.valueOf((String)arg.get('asum'));
                ar.a_b_sale = Decimal.valueOf((String)arg.get('bsum'));
            }else{
                ar.p_l_sale = Decimal.valueOf((String)arg.get('lsum'));
                ar.p_a_sale = Decimal.valueOf((String)arg.get('asum'));
                ar.p_b_sale = Decimal.valueOf((String)arg.get('bsum'));
            }

        }
        return ar;

    }

     //获取当季度的仪器 基本绩效的 基础数据汇总数据
        //工号 wono ,年 year ,季度 quater,岗位类别 post 试剂类别 cate:迈克生化,迈克免疫,迈克临检,代理 
    public static Map<String,BaseDataSum> getBaseEquipSum(String wono ,String year ,String quater,String post  ){
      System.debug('获取当季度的仪器 基本绩效的 基础数据汇总数据:'+ wono + ' '+year + ' '+quater + ' '+post);
        Map<String,BaseDataSum>  bsMap  = new Map<String,BaseDataSum>();

        for(AggregateResult arg : [select InstrumentClasses__c cate, 
            sum(ActualQuantityQ1__c) aqe1, sum(ActualQuantityQ2__c) aqe2,sum(ActualQuantityQ3__c) aqe3, sum(ActualQuantityQ4__c) aqe4 ,
            sum(BudgetQuantityQ1__c) bqe1 ,sum(BudgetQuantityQ2__c) bqe2 ,sum(BudgetQuantityQ3__c) bqe3,sum(BudgetQuantityQ4__c) bqe4 

         from SalesPerformanceDataSheet__c where EmployeeNumber__c =:wono and Year__c =:year and JobCategory__c =:post 

             and RecordType.DeveloperName in ('InstrumentPerformance','InstrumentPerformanceAdjust') and NotActive__c = false 
             group by   InstrumentClasses__c
             ]){

            String cate = (String)arg.get('cate');
            BaseDataSum b = new BaseDataSum(arg,transQuater(quater));

            bsMap.put(cate, b);
            

        }
        System.debug(bsMap);
        return bsMap;
    }

    public static BaseDataSum getBaseRegentSumForProvince(String wono , String year , String post ){
        
        BaseDataSum mkSum = new BaseDataSum();
        Set<String> cates = new Set<String>(mkregents);
        cates.add(cate_bl);
        cates.add(cate_poct);
        for(AggregateResult arg : [select ReagentCategory__c cate, 
            sum(ActualSalesQ1__c) aq1, sum(ActualSalesQ2__c) aq2,sum(ActualSalesQ3__c) aq3, sum(ActualSalesQ4__c) aq4 ,
            sum(BudgetSalesQ1__c) bq1 ,sum(BudgetSalesQ2__c) bq2 ,sum(BudgetSalesQ3__c) bq3,sum(BudgetSalesQ4__c) bq4 ,
            sum(LastYearSalesVolumeQ1__c) lq1 ,sum(LastYearSalesVolumeQ2__c) lq2 ,sum(LastYearSalesVolumeQ3__c) lq3,sum(LastYearSalesVolumeQ4__c) lq4 

         from SalesPerformanceDataSheet__c where EmployeeNumber__c =:wono and Year__c =:year and JobCategory__c =:post 

             and RecordType.DeveloperName in ('ReagentBudgetAdjust','ReagentPerformance') and NotActive__c = false 
             group by   ReagentCategory__c
             ]){

            String cate = (String)arg.get('cate');
           
            if(cates.contains(cate) ){
                mkSum.lq += transDecimal(arg.get('lq1'),0)+transDecimal(arg.get('lq2'),0)+transDecimal(arg.get('lq3'),0)+transDecimal(arg.get('lq4'),0);
                mkSum.aq += transDecimal(arg.get('aq1'),0)+transDecimal(arg.get('aq2'),0)+transDecimal(arg.get('aq3'),0)+transDecimal(arg.get('aq4'),0);
                mkSum.bq += transDecimal(arg.get('bq1'),0)+transDecimal(arg.get('bq2'),0)+transDecimal(arg.get('bq3'),0)+transDecimal(arg.get('bq4'),0);
            }

        }
        return mkSum;

    }
    //获取当季度的试剂 基本绩效的 基础数据汇总数据
    //工号 wono ,年 year ,季度 quater,岗位类别 post 试剂类别 cate:迈克生化,迈克免疫,迈克临检,代理 
    public static Map<String,BaseDataSum> getBaseRegentSum(String wono ,String year ,String quater ,String post  ){
      System.debug('获取当季度的试剂 基本绩效的 基础数据汇总数据:'+ wono + ' '+year + ' '+quater + ' '+post);
         Map<String,BaseDataSum>  bsMap  = new Map<String,BaseDataSum>();
        BaseDataSum mkSum = new BaseDataSum();
        mkSum.cate = mkregent;

    	for(AggregateResult arg : [select ReagentCategory__c cate, 
    		sum(ActualSalesQ1__c) aq1, sum(ActualSalesQ2__c) aq2,sum(ActualSalesQ3__c) aq3, sum(ActualSalesQ4__c) aq4 ,
    		sum(BudgetSalesQ1__c) bq1 ,sum(BudgetSalesQ2__c) bq2 ,sum(BudgetSalesQ3__c) bq3,sum(BudgetSalesQ4__c) bq4 ,
    		sum(LastYearSalesVolumeQ1__c) lq1 ,sum(LastYearSalesVolumeQ2__c) lq2 ,sum(LastYearSalesVolumeQ3__c) lq3,sum(LastYearSalesVolumeQ4__c) lq4 

    	 from SalesPerformanceDataSheet__c where EmployeeNumber__c =:wono and Year__c =:year and JobCategory__c =:post 

             and RecordType.DeveloperName in ('ReagentBudgetAdjust','ReagentPerformance') and NotActive__c = false 
           	 group by 	ReagentCategory__c
             ]){

    		String cate = (String)arg.get('cate');
    		BaseDataSum b = new BaseDataSum(arg,transQuater(quater));

    		bsMap.put(cate, b);
            if(mkregents.contains(cate)){
                mkSum.lq += b.lq;
                mkSum.aq += b.aq;
                mkSum.bq += b.bq;
            }

    	}
        bsMap.put(mkregent, mkSum);
        System.debug(bsMap);
    	return bsMap;
    } 
    public static String transQuater(String quater){

    	if(quater == '四季度' || quater == '4')return '4';
      	if(quater == '三季度' || quater == '3')return '3';
    	if(quater == '二季度' || quater == '2')return '2';
    	if(quater == '一季度' || quater == '1')return '1';
  		return null;
    }
    public static String transQuater(Integer quater){
        if(quater == 1) return '一季度';
        if(quater == 2) return '二季度';
        if(quater == 3) return '三季度';
        if(quater == 4) return '四季度';
        return null;
    }
    //从名单录入表中获取基本绩效考核占比
    public static BaseBean getBaseRito(String wono ,String year ){
    	//从名单录入表中获取基本绩效考核占比
        System.debug('从名单录入表中获取基本绩效考核占比');
        System.debug(wono +' '+year);
    	BaseBean br = new BaseBean();
        List<SalesPerformanceDataSheet__c> sps = [select Id ,Company__c,Name__c,ProductJobCategory__c,AreaJobCategory__c,
        IncrementalCcategory__c,AssessmentCategory__c,AreaReagentRate__c,AreaSurrogateReagentRate__c,IncrementalJobCategory__c,
        AreaBloodCorpuscleRate__c,AreaC800Rate__c,Areai1000Rate__c,Areai3000Rate__c,AreaInstrumentRate__c,
        BiochemistryRate__c,AreaOverdueRate__c,AreaSaccharifyRate__c,AreaBloodTypeRate__c,AreaBloodClottingRate__c,
        C800Rate__c,i1000Rate__c,i3000Rate__c,InstrumentRate__c,AgentProductRate__c,ClinicalLaboratoryRate__c,ImmunityRate__c,
        SuperiorEvaluationRate__c,OverdueRate__c,SaccharifyRate__c,BloodTypeRate__c,BloodClottingRate__c,BloodCorpuscleRate__c
        from SalesPerformanceDataSheet__c where EmployeeNumber__c =:wono and Year__c =:year 
        and Recordtype.DeveloperName ='PerformanceUser' limit 1 ];
    	//[select ]
        SalesPerformanceDataSheet__c sp = sps.isEmpty() ? new SalesPerformanceDataSheet__c() : sps.get(0);
        System.debug(sp);
        br.name = sp.Name__c;
        br.company = Sp.Company__c;
    	br.post = sp.AssessmentCategory__c;// '销售员';
    	br.incr_post = sp.IncrementalJobCategory__c; //'直销销售员';
    	br.a_post = sp.AreaJobCategory__c; //'直销销售员';
    	br.p_post = sp.ProductJobCategory__c; //'产品线销售人员';

    	br.a_mkregent_rito = transPercentToDecimal(sp.AreaReagentRate__c  ) ; //0.55;
        System.debug(br.a_mkregent_rito);
    	br.a_agent_rito = transPercentToDecimal(sp.AreaSurrogateReagentRate__c )  ; //0.15;
    	br.a_equip_rito = transPercentToDecimal(sp.AreaInstrumentRate__c )  ; //0;
    	br.a_i3000_rito = transPercentToDecimal(sp.Areai3000Rate__c )  ; //0.30;
    	br.a_i1000_rito = transPercentToDecimal(sp.Areai1000Rate__c )  ; //0.15;
    	br.a_c800_rito = transPercentToDecimal(sp.AreaC800Rate__c  );//0.10;
    	br.a_xq_rito =transPercentToDecimal(sp.AreaBloodCorpuscleRate__c);// 0.20;
    	br.a_lx_rito = transPercentToDecimal(sp.AreaBloodClottingRate__c);//0.15;
    	br.a_xx_rito =transPercentToDecimal(sp.AreaBloodTypeRate__c);// 0.05;
    	br.a_th_rito =transPercentToDecimal(sp.AreaSaccharifyRate__c);//0.05;

        br.aRitoMap = new Map<String,Decimal>();
        br.aRitoMap.put(equip_i1000, br.a_i1000_rito);
        br.aRitoMap.put(equip_i3000, br.a_i3000_rito);
        br.aRitoMap.put(equip_c800, br.a_c800_rito);
        br.aRitoMap.put(equip_xq, br.a_xq_rito);
        br.aRitoMap.put(equip_lx, br.a_lx_rito);
        br.aRitoMap.put(equip_xx, br.a_xx_rito);
        br.aRitoMap.put(equip_th, br.a_th_rito);

    	
    	br.a_overtime_rito =transPercentToDecimal(sp.AreaOverdueRate__c);// 0.3;


    	br.p_mksh_rito  = transPercentToDecimal(sp.BiochemistryRate__c);//0.30;
    	br.p_mkmy_rito = transPercentToDecimal(sp.ImmunityRate__c);//0.30;
    	br.p_mklj_rito = transPercentToDecimal(sp.ClinicalLaboratoryRate__c);//0.35;

    	br.p_agent_rito =transPercentToDecimal(sp.AgentProductRate__c);// 0.15;
    	br.p_equip_rito =transPercentToDecimal(sp.InstrumentRate__c);// 0;
    	br.p_i3000_rito = transPercentToDecimal(sp.i3000Rate__c);//0.30;
    	br.p_i1000_rito =transPercentToDecimal(sp.i1000Rate__c);// 0.15;
    	br.p_c800_rito =transPercentToDecimal(sp.C800Rate__c);// 0.10;
    	br.p_xq_rito =transPercentToDecimal(sp.BloodCorpuscleRate__c);// 0.20;
    	br.p_lx_rito = transPercentToDecimal(sp.BloodClottingRate__c);//0.15;
    	br.p_xx_rito = transPercentToDecimal(sp.BloodTypeRate__c);//0.05;
    	br.p_th_rito = transPercentToDecimal(sp.SaccharifyRate__c);//0.05;
    	br.p_overtime_rito = transPercentToDecimal(sp.OverdueRate__c);//0.3;
    	br.p_sjpj_rito =transPercentToDecimal(sp.SuperiorEvaluationRate__c);// 0.9;

        br.pRitoMap = new Map<String,Decimal>();
        br.pRitoMap.put(equip_i1000, br.p_i1000_rito);
        br.pRitoMap.put(equip_i3000, br.p_i3000_rito);
        br.pRitoMap.put(equip_c800, br.p_c800_rito);
        br.pRitoMap.put(equip_xq, br.p_xq_rito);
        br.pRitoMap.put(equip_lx, br.p_lx_rito);
        br.pRitoMap.put(equip_xx, br.p_xx_rito);
        br.pRitoMap.put(equip_th, br.p_th_rito);



    	return br;

    }

    //增量绩效计算 基本数据 区域 
    public static  Map<String,List<IncreaseData>>  getIncreaseData(String wono ,String year,String quater , BaseBean br  ){
       String post = br.incr_post ;
      System.debug('增量绩效计算 基本数据 区域:'+ wono + ' '+year + ' '+quater + ' '+post);

       if(String.isBlank(post) ||  (post != saler_cpx  && post != saler_zx && post != saler_fx ) )  return new  Map<String,List<IncreaseData>> ();
        //market_zx
        Set<String> markets = post == saler_cpx ?  new Set<String>{market_fx} : post == saler_zx ? new Set<String>{market_zx} : new Set<String>{market_fx}   ;


        Map<String,List<IncreaseData>> cateMap = new Map<String,List<IncreaseData>>();

        for ( AggregateResult arg : [select  IncrementalCcategory__c cate, Category__c type, 
            sum(ActualSalesQ1__c) aq1, sum(ActualSalesQ2__c) aq2,sum(ActualSalesQ3__c) aq3, sum(ActualSalesQ4__c) aq4 ,
            sum(LastYearSalesVolumeQ1__c) lq1 ,sum(LastYearSalesVolumeQ2__c) lq2 ,sum(LastYearSalesVolumeQ3__c) lq3,sum(LastYearSalesVolumeQ4__c) lq4 
             from SalesPerformanceDataSheet__c 
        where EmployeeNumber__c =:wono and Year__c=:year and Quarter__c=:quater  and JobCategory__c =:post 
        and SalesMarket__c in:markets 
        and RecordType.DeveloperName in ('ReagentIncrementalPerformance','ReagentIncrementalPerformanceAdjust') and NotActive__c = false 
             group by   IncrementalCcategory__c,Category__c  ] ) {


            String cate = (String)arg.get('cate');

            List<IncreaseData> tmp = cateMap.containsKey(cate) ? cateMap.get(cate) : new List<IncreaseData>();
            
            tmp.add(new IncreaseData(arg,quater));
            
            cateMap.put(cate, tmp);

        }


        return cateMap;

    }




    //转换数值
    public  static Decimal transDecimal(Object obj,Decimal defaultVal ){
    	if(defaultVal == null ) defaultVal = 0;
    	if(obj == null )return defaultVal;
    	if(obj instanceof String){
    		String d = String.valueOf(obj).trim();
    		try {
    		    return Decimal.valueOf(d);
    		}
    		catch (Exception e) {
    		    return defaultVal;
    		}
    	
    	}
    	if(obj instanceof Decimal) return (Decimal)obj;
    	return Decimal.valueOf(String.valueOf(obj));
    }

    //自产提成比例
    public class RitoBean{
       // public Decimal rito ;//增长率
        public Decimal a_normal_rito  = 0;//非特殊项目
        public Decimal a_special_rito  = 0; //特殊项目
        public Decimal p_normal_rito  = 0;// 产品线 非特殊项目
        public Decimal p_special_rito = 0 ; //产品线 特殊项目

        public Decimal a_in_rito = 0;//代理 目标内提成比例
        public Decimal a_out_rito = 0;//代理 目标外提成比例
        public Decimal p_in_rito = 0;//代理 目标内提成比例
        public Decimal p_out_rito = 0;//代理 目标外提成比例
        public Decimal finish_rito = 0;//代理 完成率
        public Decimal increase_rito = 0;//代理 增长率
        public RitoBean(){}
        public RitoBean (Decimal a_nr ,Decimal a_sr ,Decimal p_nr ,Decimal p_sr   ){
            a_normal_rito = a_nr;
            a_special_rito = a_sr;
            p_normal_rito = p_nr;
            p_special_rito = p_sr;

        }
    }
    //考核指标
    public class CalcStand{
    	public String wono ;//工号

    	public Decimal a_overtime_rito  = 0;//超期得分(区域)
    	public Decimal p_overtime_rito = 0;//超期得分(产品线)
    	public Decimal sjpj_rito = 0;//上级评价
    	public Decimal crm_minus = 0;//crm扣款
    	public Decimal dz_minus = 0;//对账扣款
    	public Decimal overtime_minus = 0;//超期扣款
    	public Decimal performance_minus = 0;//销售绩效扣款

    }

    public class IncreaseData{
        public String cate ;//试剂类别 迈克生化,迈克免疫,迈克临检
        public String type; //特殊项目 非特殊项目
        public Decimal lq =0 ;//去年
        public Decimal aq = 0 ; //今年销售
        public IncreaseData(AggregateResult arg,String quater){

            cate = (String)arg.get('cate');
            type = (String)arg.get('type');
             lq = SalePerformanceDataCalcUtil.transDecimal(arg.get('lq'+quater),null );
             aq = SalePerformanceDataCalcUtil.transDecimal(arg.get('aq'+quater),null );

        }

    }

    public class IncreaseDataBean{
        public String year; //年
        public String quater ;//季度
        public String cate ;//
        //区域
        public Decimal a_increase_rito;//增长率
        public Decimal a_l_special_sale;//去年 特殊 项目 销售
        public Decimal a_l_normal_sale;//去年 非特殊 项目 销售
        public Decimal a_a_special_sale;//今年 特殊 项目 销售
        public Decimal a_a_normal_sale;//今年 非特殊 项目 销售
        //产品线
        public Decimal p_increase_rito;//增长率
        public Decimal p_l_special_sale;//去年 特殊 项目 销售
        public Decimal p_l_normal_sale;//去年 非特殊 项目 销售
        public Decimal p_a_special_sale;//今年 特殊 项目 销售
        public Decimal p_a_normal_sale;//今年 非特殊 项目 销售

        public Decimal special_base;//特殊项目提层基数
        public Decimal normal_base;//非特殊项目提成基数

        public Decimal special_rito;//特殊项目提成比例
        public Decimal normal_rito;//非特殊项目提成比例
        public Decimal sale_rito;//销售员增量计算结果
        public IncreaseDataBean(){

            a_increase_rito = 0 ;
            a_l_special_sale = 0;
            a_l_normal_sale = 0;
            a_a_special_sale = 0;
            a_a_normal_sale = 0;

            p_increase_rito = 0;
            p_l_normal_sale = 0;
            p_l_special_sale = 0 ;
            p_a_normal_sale = 0;
            p_a_special_sale = 0 ; 
            special_base = 0 ;
            normal_base = 0 ;

            special_rito = 0 ; 
            normal_rito = 0 ;
            sale_rito = 0 ; 

        }

    }
    public class IncreaseResult{
        
        public String year; //年
        public String quater ;//季度
       // public String cate ;//

        public Decimal increase_rito = 0;
        public Decimal rito  = 0;//贡献率
        public Decimal  money_rito = 0 ;//增量发放

    }

    public class AgentResult{

        public String year;
        public Decimal a_mkA_rito = 0 ;//自产试剂达成率
        public Decimal a_mkI_rito = 0 ;//自产试剂增长率
        public Decimal a_l_sale = 0 ;//去年
        public Decimal a_a_sale = 0 ;//今年
        public Decimal a_b_sale = 0 ;//目标
        public Decimal a_in_rito = 0  ;//目标内增量提成比例
        public Decimal a_out_rito = 0 ;//目标外增量提成比例;
        public Decimal a_in_base = 0 ;//目标内增量提成基数
        public Decimal a_out_base  = 0 ;//目标内增量提成基数
        public Decimal a_over_base = 0;//超目标提成基数

        public Decimal p_mkA_rito = 0 ;//自产试剂达成率
        public Decimal p_mkI_rito = 0 ;//自产试剂增长率
        public Decimal p_l_sale = 0 ;//去年
        public Decimal p_a_sale = 0 ;//今年
        public Decimal p_b_sale = 0 ;//目标
        public Decimal p_in_rito = 0  ;//目标内增量提成比例
        public Decimal p_out_rito = 0 ;//目标外增量提成比例;
        public Decimal p_in_base = 0 ;//目标内增量提成基数
        public Decimal p_out_base  = 0 ;//目标内增量提成基数
        public Decimal p_over_base = 0;//超目标提成基数

        public Decimal sale_rito = 0;

    }

    public class ProvinceResult{
        public String year ; 
        public Decimal l_sale = 0; 
        public Decimal b_sale= 0;
        public Decimal a_sale= 0;

        public Decimal b_increase_rito= 0;//自产目标增长率
        public Decimal tc_rito= 0;//自产目标达成则算
        public Decimal tb_increase_rito= 0;//自产同比达成（增长率）
        public Decimal yq_rito= 0 ;//仪器达成率
        public Decimal zl_rito = 0;//增量系数则算
    }

    //基本绩效的 基础数据汇总数据
    public class BaseDataSum{
    	public String cate;//试剂类别:迈克生化,迈克免疫,迈克临检,代理  仪器类别:i3000,i1000,c800,血球,凝血,血型,糖化
    	public Decimal lq = 0;//去年销售额
    	public Decimal aq = 0;//今年销售额度
    	public Decimal bq = 0;//今年目标
        //仪器
        public Decimal aqe = 0;//今年安装数
        public Decimal bqe = 0;//今年目标数
        public Decimal ertio = 0;

    	public BaseDataSum(){}
    	public BaseDataSum(AggregateResult arg,String quater ){

    		 cate = (String)arg.get('cate');
             try{
    		      lq = SalePerformanceDataCalcUtil.transDecimal(arg.get('lq'+quater),null );
             }catch(Exception e){}
             try{
    		      aq = SalePerformanceDataCalcUtil.transDecimal(arg.get('aq'+quater),null );
             }catch(Exception e){}
             try{
    		      bq = SalePerformanceDataCalcUtil.transDecimal(arg.get('bq'+quater),null );
             }catch(Exception e){}
             try{
                aqe = SalePerformanceDataCalcUtil.transDecimal(arg.get('aqe'+quater),null );
             }catch(Exception e){}
             try{
                bqe = SalePerformanceDataCalcUtil.transDecimal(arg.get('bqe'+quater),null );
             }catch(Exception e){}
             try {
                 ertio = aqe / bqe ;
                 if(ertio > 0.8 )ertio = 1;
             }
             catch (Exception e) {
                  ertio  = 0;
             }
             
            
    	}

    }

    public class BaseCalcBean{
        public String title ;
        public String year ;
        public String quater;
        public Decimal a_mkregent = 0;
        public Decimal a_mksh = 0 ;
        public Decimal a_mkmy = 0;
        public Decimal a_mklj = 0;
        public Decimal a_agent = 0;

        public Decimal p_mkregent = 0;
        public Decimal p_mksh = 0 ;
        public Decimal p_mkmy = 0;
        public Decimal p_mklj = 0;
        public Decimal p_agent = 0;
        public BaseCalcBean(){}
        public BaseCalcBean(String t , String y , String q ){
            title = t;
            year = y;
            quater = q ; 
        }


    }
     public class BaseEquipCalcBean{
        public String title;
        public String year ;
        public String quater;
        public Decimal a_i3000  = 0;
        public Decimal a_i1000 = 0 ;
        public Decimal a_c800 = 0;
        public Decimal a_xq = 0;
        public Decimal a_lx = 0;
        public Decimal a_xx = 0;
        public Decimal a_th = 0;

        public Decimal p_i3000  = 0;
        public Decimal p_i1000 = 0 ;
        public Decimal p_c800 = 0;
        public Decimal p_xq = 0;
        public Decimal p_lx = 0;
        public Decimal p_xx = 0;
        public Decimal p_th = 0;
        public BaseEquipCalcBean(){}
        public BaseEquipCalcBean(String t , String y , String q ){
            title = t;
            year = y;
            quater = q ; 
        }


    }
    //基本绩效
    public class BaseBean{

        public String year; //年
        public String quater ;//季度
        public String company ;
        public String name;

    	public String a_post;//区域岗位类别:直销销售员,分销销售员, 直销管理人员, 分销管理人员
    	public String p_post ;//产品线岗位类别:产品线销售人员,产品线管理人员,省区管理人员
    	public String incr_post;//增量提成岗位类别:直销销售员,分销销售员, 直销管理人员, 分销管理人员,产品线销售人员,产品线管理人员,省区管理人员
    	public String post;//考核类别:销售员,销售管理人员
    	//区域
        public  Map<String,Decimal> aRitoMap ;
    	public Decimal a_mkregent_rito  = 0;//迈克试剂
    	public Decimal a_agent_rito = 0;//代理试剂
    	public Decimal a_equip_rito = 0;//仪器
    	public Decimal a_i3000_rito = 0;//i3000
    	public Decimal a_i1000_rito = 0;//i1000
    	public Decimal a_c800_rito = 0;//c800

		public Decimal a_xq_rito = 0;//血球
    	public Decimal a_lx_rito = 0;//凝血
    	public Decimal a_xx_rito = 0;//血型
    	public Decimal a_th_rito = 0;//糖化

    	public Decimal a_overtime_rito = 0;//超期
    	//产品线
        public  Map<String,Decimal> pRitoMap ;
    	public Decimal p_mksh_rito = 0;
    	public Decimal p_mkmy_rito = 0;
    	public Decimal p_mklj_rito = 0;

    	public Decimal p_agent_rito = 0;
    	public Decimal p_equip_rito = 0;//仪器
    	public Decimal p_i3000_rito = 0;
    	public Decimal p_i1000_rito = 0;
    	public Decimal p_c800_rito = 0;

		public Decimal p_xq_rito = 0;
    	public Decimal p_lx_rito = 0;
    	public Decimal p_xx_rito = 0;
    	public Decimal p_th_rito = 0;

    	public Decimal p_overtime_rito = 0;//
    	public Decimal p_sjpj_rito = 0;//上级评价

    	public Decimal baseResult = 0;//基本绩效得分
    	public Decimal crm_minus = 0;//crm扣款
    	public Decimal dz_minus = 0;//对账扣款
    	public Decimal overtime_minus = 0;//超期扣款
    	public Decimal performance_minus = 0;//绩效扣款

    }

       //基本绩效计算
    //wono 工号 ,年 year ,季度 quater
/*
    public static BaseBean calcBase(String wono ,String year ,String quater ){
        //目标绩效数据:
        BaseBean target = new BaseBean();
        target.year = year ; 
        target.quater = quater;

        //1.获取考核占比
        BaseBean br = getBaseRito(wono,year );
        //2.获取超期考核指标
        CalcStand cs =  getCalcStand(wono,year);
        //只有销售员进行计算
        //if(br.post  != base_post)return;

        //3.获取当季度的基本绩效的 基础数据汇总数据 
        //3.1 区域销售汇总数据
        if(String.isNotBlank(br.a_post)){

            Map<String,BaseDataSum>   baseAreaSums = getBaseRegentSum(wono,year,quater,br.a_post);
            //迈克试剂
            target.a_mkregent_rito  =  calcBaseRegentRito(baseAreaSums, mkregent, br.post);   
            //代理
            target.a_agent_rito =   calcBaseRegentRito(baseAreaSums, regentCate, br.post); 
            //仪器
            target.a_equip_rito =   calcBaseEquipRito(getBaseEquipSum(wono,year,quater,br.a_post),br,true );
            //超期
            target.a_overtime_rito = cs.a_overtime_rito;

        }
        
        //2.2 产品线销售汇总数据 
        if(String.isNotBlank(br.p_post)){

            Map<String,BaseDataSum>  basePLineSums = getBaseRegentSum(wono,year,quater,br.p_post);

            //迈克生化
            target.p_mksh_rito = calcBaseRegentRito(basePLineSums, cate_sh, br.post);
            //迈克免疫
            target.p_mkmy_rito = calcBaseRegentRito(basePLineSums, cate_my, br.post);
            //迈克临检
            target.p_mklj_rito = calcBaseRegentRito(basePLineSums, cate_lj, br.post);
            //代理
            target.p_agent_rito =   calcBaseRegentRito(basePLineSums, regentCate, br.post); 
            //仪器
            target.p_equip_rito =   calcBaseEquipRito(getBaseEquipSum(wono,year,quater,br.p_post),br,false );
            //超期
            target.p_overtime_rito= cs.p_overtime_rito;
            //上级评价
            target.p_sjpj_rito = cs.sjpj_rito;


        }       
        //4.开始计算达成率
        target.baseResult = multi(target.a_mkregent_rito,br.a_mkregent_rito )
                            +multi(target.a_agent_rito,br.a_agent_rito )
                            +multi(target.a_equip_rito,br.a_equip_rito )
                            +multi(target.a_overtime_rito,br.a_overtime_rito )

                            +multi(target.p_mksh_rito,br.p_mksh_rito )
                            +multi(target.p_mkmy_rito,br.p_mkmy_rito )
                            +multi(target.p_mklj_rito,br.p_mklj_rito )
                            +multi(target.p_agent_rito,br.p_agent_rito )
                            +multi(target.p_equip_rito,br.p_equip_rito )
                            +multi(target.p_overtime_rito,br.p_overtime_rito )
                            +multi(target.p_sjpj_rito,br.p_sjpj_rito );

        target.crm_minus = br.crm_minus;
        target.dz_minus = br.dz_minus;
        target.overtime_minus = br.overtime_minus;
        target.performance_minus = br.performance_minus;

        return target;
    }
*/

}